Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=utf-8');
- $servername = 'localhost';
- $username = 'names';
- $password = 'password';
- $dbname = 'base';
- $array_attrib = array();
- //название группы атрибутов которые будем проставлять
- if(isset($_POST['name']) && !empty($_POST['name'])) {
- $group_atrib = htmlspecialchars($_POST['name']);
- }
- else{
- $group_atrib = 'не указана';
- }
- if(isset($_POST['id']) && !empty($_POST['id'])) {
- //id-категории товаров в которой нужно проставить атрибуты из группы атрибутов $group_atrib
- $cat_id = htmlspecialchars($_POST['id']);
- //таблица связки продукт-категория
- }
- else{
- $cat_id = 0;
- }
- $tbl_prodcat = 'oc_product_to_category';
- //таблица с именами категорий
- $tbl_catdescr = 'oc_category_description';
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Строим запрос
- $sql = "SELECT $tbl_prodcat.product_id, $tbl_catdescr.name FROM $tbl_prodcat, $tbl_catdescr WHERE $tbl_prodcat.category_id = '$cat_id' AND $tbl_prodcat.category_id = $tbl_catdescr.category_id";
- $sql2 = "SELECT oc_attribute_description.name as descr, oc_attribute_group_description.name as names FROM `oc_attribute_description`, `oc_attribute_group_description`, `oc_attribute` WHERE oc_attribute.attribute_id = oc_attribute_description.attribute_id AND oc_attribute.attribute_group_id = oc_attribute_group_description.attribute_group_id ORDER BY oc_attribute_group_description.name";
- $sql3 = "SELECT oc_attribute.attribute_id as namesid FROM `oc_attribute_description`, `oc_attribute_group_description`, `oc_attribute` WHERE oc_attribute.attribute_id = oc_attribute_description.attribute_id AND oc_attribute.attribute_group_id = oc_attribute_group_description.attribute_group_id AND oc_attribute_group_description.name = '$group_atrib'";
- //получаем массив id атрибутов по категории
- $result3 = $conn->query($sql3);
- if ($result3->num_rows > 0) {
- while($row = $result3->fetch_assoc()) {
- //echo "//" .$row["namesid"]."<br>";
- $array_attrib[] = $row["namesid"];
- }
- }
- // Получаем результаты по aтрибутам
- $result = $conn->query($sql2);
- if ($result->num_rows > 0) {
- // output data of each row
- echo "<!DOCTYPE html>
- <html>
- <head>
- <style>
- table {
- font-family: arial, sans-serif;
- border-collapse: collapse;
- width: 100%;
- }
- td, th {
- border: 1px solid #dddddd;
- text-align: left;
- padding: 8px;
- }
- tr:nth-child(even) {
- background-color: #dddddd;
- }
- </style>
- </head>
- <body>
- <table>
- <tr>
- <th>Группа атрибутов</th>
- <th>Название атрибута</th>
- </tr>";
- while($row = $result->fetch_assoc()) {
- echo "<tr><td>" . $row["names"]. "</td><td>".$row["descr"]."</td></tr>";
- }
- } else {
- echo "0 results";
- }
- echo "
- </table><hr>
- <form action=\"\" method=\"post\">
- <p><b>ID категории</b>
- <input type=\"text\" size=\"40\" name=\"id\">
- <b>Название группы атрибутов</b>
- <input type=\"text\" size=\"40\" name=\"name\">
- <input type=\"submit\">
- </form>
- ";
- // Получаем результаты
- echo "<textarea id=\"bar\" rows=\"100\" cols=\"185\">";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- foreach ($array_attrib as &$value) {
- $product_id = $row["product_id"];
- $language_id = '1';
- $text = 'заполнить';
- //echo "Товар id: " . $row["product_id"]. " / категория: " . $row["name"]." / номер атрибута: ".$value."<br>";
- $sql4 = "INSERT INTO `oc_product_attribute` (product_id, attribute_id, language_id, text) VALUES ('$product_id', '$value', '$language_id', '$text') ON DUPLICATE KEY UPDATE product_id='$product_id', attribute_id='$value'";
- //$sql4 = "UPDATE `oc_product_attribute` SET attribute_id = '$value' WHERE product_id = '$product_id' AND attribute_id = '$value'";
- //$sql4 = "DELETE FROM `oc_product_attribute` WHERE product_id = '$product_id'";
- echo $sql4.";\n";
- }
- }
- } else {
- echo "0 results";
- }
- $conn->close();
- echo "</textarea></body></html>";
Add Comment
Please, Sign In to add comment