Creating a tag cloud using MySQL and PHP

I am creating a tag cloud. I have a table called tags with the number 'id' and row 'tag'.

Each tag "tag" will be a tag like on this site. Imagine a tag called "foo" for this example.

Each line of 'id' will be the identifier of the web pages marked with something - 'foo', in this example.

Thus, any arbitrary string may look like this:

foo | 3 6 16 39 43 58 38 12 55

How to create a function that checks the entire table for the existence of the $ tag, and if it exists, add a space and $ id to the 'id' line for this tag. If the tag does not exist in my table, add the tag and add the identifier.

The code I have (half-php, half-pseudo) is as follows:

if($tag doesnt exist in table)
{
     mysql_query("INSERT INTO tags (tag, id) VALUES ('$tag', '$id'");
}
if($tag exists in table)
{
     mysql_query("...append somehow... $id . " " WHERE tag = '$tag'");
}

, SQL , . ?

+3
4

. , , item_tags ( - , .) , item_tags item_it ( id). 1 . , 3 , item_tags 3 . , , .

, , , , , . , . , . , , , .

HTH

+1

tags? -, ?

:

SELECT id FROM tags WHERE tag = `my-tag`;

:

INSERT INTO tags (tag, id) VALUES ('my-tag', newWebpageID);

-:

DELETE FROM tags WHERE id = webpageID;
0

(.. ):

(, , ) ( ) ContentTags ( )

"abc" "foo" "bar".

ContentID (1 ) Content (abc). : TagID ( 1, 2) TagText (foo, bar) ContentTags ContentTagID (1, 2), ContentID (1, 1) TagID (1, 2).

, ( ) ( ContentTags).

, , ContentTags, , .

, , (, "SELECT TagID FROM Tags WHERE TagText = $tagText" ). , , ContentTags TagID- ItemID , .

, ,

0

.

, : 1, " ", 1, " ", 1, " ". INSERT IGNORE, . , .

0

Source: https://habr.com/ru/post/1792362/


All Articles