<?PHP
$arr =
array("color"=>array(
array(
"id"=> "1",
"name"=> "Цвет",
"value"=> "красный",
"photo"=> "http://google.com/"),
array(
"id"=> "2",
"name"=> "Цвет",
"value"=> "зеленый",
"photo"=> "http://google.com/"
)
),
"razmer"=>array(
array(
"id"=> "1",
"name"=> "Размер",
"value"=> "900х2000",
"photo"=> "http://google.com/"
),
array(
"id"=> "2",
"name"=> "Размер",
"value"=> "800х2000",
"photo"=> "http://google.com/"
),
array(
"id"=> "3",
"name"=> "Размер",
"value"=> "700х2000",
"photo"=> "http://google.com/"
),
array(
"id"=> "4",
"name"=> "Размер",
"value"=> "600х2000",
"photo"=> "http://google.com/"
)
)
);
function getMix($arr,$charr = null,$n = null){
if(!isset($n))
$n = 0;
$tmpArr = array_values($arr);
if(!isset($charr))
$charr = array();
$str = "";
for($i = 0; $i < count($tmpArr[$n]);$i++){
$mycharr = $charr;
array_push($mycharr,$tmpArr[$n][$i]["value"]);
if($n < count($tmpArr)-1)
$str .= getMix($arr,$mycharr,$n+1);
else{
for($j = 0; $j < count($mycharr);$j++)
$str .= $mycharr[$j]." ";
$str .= "<br>";
}
}
return $str;
}
echo getMix($arr);
?>
красный900х2000
красный800х2000
красный700х2000
красный600х2000
зеленый900х2000
зеленый800х2000
зеленый700х2000
зеленый600х2000
Логин root
Пароль 123456
Хост localhost
Порт 3306
Имя: my_data
Настраивается в data.php
Имя: images
Поля
id int autoincrement
url varchar 255
post_id int
Имя: posts
Поля
id int autoincrement
title varchar 50
description text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body{
background: #333333;
}
.post{
color:aliceblue;
width:60%;
margin: auto;
border: 5px solid #FFF;
margin-top:25px;
}
.post .title{
font-size:1.4em;
padding: 15px;
background:#660099;
}
.post .description{
padding: 15px;
background:#330099;
}
.post .images img{
border-radius: 20px;
margin: 20px auto;
width: 50%;
display: block;
}
.post .images{
padding: 15px;
max-height: 500px;
overflow: overlay;
background:#660099;
}
</style>
</head>
<body>
<?PHP
require_once "data.php";
$con = sql_connect();
$sql = "SELECT id,title,description FROM posts LIMIT 20";
$res = $con->query($sql);
$bar = "";
while($row = $res->fetch_assoc()){
$bar .= "<div class='post' data-postid={$row["id"]}'>
<div class='title'>{$row["title"]}</div>
<div class='description'>{$row["description"]}</div>
<div class='images'>";
$sql = "SELECT url FROM images WHERE post_id=$row[id]";
$imgs = $con->query($sql);
while($img = $imgs->fetch_row())
$bar .= "<img src=\"$img[0]\">";
$bar .= "
</div>
</div>";
}
echo $bar;
?>
</body>
</html>
<?PHP
define("DB_LOGIN","root");
define("DB_PASS","123456");
define("DB_HOST","localhost");
define("DB_NAME","my_data");
define("DB_PORT","3306");
function sql_connect(){
$con = new mysqli(DB_HOST, DB_LOGIN, DB_PASS, DB_NAME,DB_PORT);
if ($con->connect_errno) {
echo "Нет доступа к БД! Ошибка: " . $con->connect_error;
return false;
}
return $con;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script>
document.addEventListener("DOMContentLoaded",function(){
document.all.addFoto.addEventListener("click",function(){
var el = document.createElement("input");
el.name = "foto[]";
el.type = "file";
el.accept="image/*";
document.all.addBtn.appendChild(el)
});
});
</script>
<style>
label,input{
display:block;
margin-top:10px;
}
</style>
<body>
<form action="addScript.php" method="post" enctype="multipart/form-data">
<label >Заголовок<input type="text" name="title"></label>
<label >Описание<input type="text" name="description"></label>
<input type="button" id="addFoto" value="Добавить фото">
<div id="addBtn"></div>
<input type="submit" value="Отправить" />
</form>
</body>
</html>
<?PHP
require_once "data.php";
$arr = [];
if(isset($_FILES["foto"])){
$dir = "upload/images";
if(!is_dir($dir))
mkdir($dir,0777,true);
for($i = 0; $i < count($_FILES["foto"]["name"]);$i++){
if($_FILES["foto"]["error"][$i] == 0 && preg_match("/^image/",$_FILES["foto"]["type"][$i])){
array_push($arr,$dir."/".time()."_".preg_replace("/[а-яА-Я\s]/i", '', $_FILES["foto"]["name"][$i]));
move_uploaded_file($_FILES["foto"]["tmp_name"][$i],end($arr));
}
}
}
$title = trim(htmlspecialchars($_POST["title"]));
$description = trim(htmlspecialchars($_POST["description"]));
if($title && $description && $con = sql_connect()){
$sql = "INSERT INTO posts(title,description) VALUES('$title','$description')";
$con->query($sql);
$sql = "SELECT MAX(id) FROM posts";
$res = $con->query($sql);
$row = $res->fetch_row();
for($i = 0; $i < count($arr);$i++){
$sql = "INSERT INTO images(url,post_id) VALUES('$arr[$i]','$row[0]')";
$con->query($sql);
}
}
else
echo "Error: no data!";
$con->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form method="post" action="search.php">
<input type="text" name="search" id="search_box" class='search_box'/>
<input type="submit" value="Поиск" class="search_button" /><br />
</form>
</body>
</html>
<?PHP
function search ($query)
{
$query = trim($query);
$query = htmlspecialchars($query);
if (!empty($query))
{
if (strlen($query) < 1) {
$text = '<p>Слишком короткий поисковый запрос.</p>';
} else if (strlen($query) > 128) {
$text = '<p>Слишком длинный поисковый запрос.</p>';
} else {
$con = mysqli_connect("localhost","root","123456","my_bd_name") or die(mysqli_error($con));//Тут твои значения
$q = "SELECT * FROM `videos` WHERE `title` LIKE '%$query%'";
$result = mysqli_query($con,$q);
if (mysqli_num_rows($result) > 0) {
$num = mysqli_num_rows($result);
$text = '<p>По запросу <b>'.$query.'</b> найдено '.$num. ' совпадений</p>';
while ($row = mysqli_fetch_assoc($result)){
$text .= "<div id='film{$row['id']}'>";
$text .= "<p>Название: {$row['title']}</p>";
$text .= "<p>Описание: {$row['description']}</p>";
$text .= "<p>Жанр: {$row['category']}</p>";
$text .= "</div>";
}
} else {
$text = '<p>По вашему запросу ничего не найдено.</p>';
}
}
} else {
$text = '<p>Задан пустой поисковый запрос.</p>';
}
return $text;
}
?>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
if (isset($_POST['search'])) {
$search_result = search ($_POST['search']);
echo $search_result;
}
}
?>
$(function() {
$(".contact_form input[type=checkbox]").bind("change", function(e) {
if ($(this).is(':checked'))
$(this).parent().parent().find("input[type=tel]").removeAttr("required");
else
$(this).parent().parent().find("input[type=tel]").attr("required", true);
})
});
function handleString(str){
return str.replace(/\[.[^\]]{2,}\]/g, function(arg1) {
name = arg1.replace(/^\[@/, "").replace(/\]$/, "");
return "<a href=\"/user/" + name + "\">@" + name + "</a>"
});
}