Hello everyone, there is a need to finish tagging the blog. And here's the idea, if the post came ['keywords'], then we break it (separated by commas). Next, we take out the tags from the database, and compare new tags with them, if there are the same ones, then we do nothing, if not, we add the tag name to the database.
Here is the code:
// Допустим это теги которые пришли с $_GET $text = "text1,text2,text3,программирование,text5,text6,text7"; // Разобьём $data = explode(",", $text); // Возьмём теги из БД $sql = mysql_query("SELECT name FROM keywords") or die("Error #345738"); // есть ли они вообще if (mysql_num_rows($sql)) { while ($result = mysql_fetch_assoc($sql)) { // занесём все теги из бд в массив $row[] = $result; } // Переберём массив row foreach ($row as $name) { // переберём входящий массив $_GET foreach ($data as $postname) { // если нет в бд такого массива, занесём его туда if (!$name == $postname) { mysql_query("INSERT INTO keywords (name) VALUES ('" . $postname . "')"); } } } } else { }
the problem is that nothing happens, in the database there are already a couple of tags.