Bonjour,
Voila j'ai un petit problème avec un UPDATE qui ne fait rien.
En fait je suis un train de créer un nuage de tags pour mon site, mais avant de commencer à coder il faut que je remplisse la table tags :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 `tags` ( `id` int(11) NOT NULL auto_increment, `tag` varchar(255) NOT NULL default '', `articles_ids` text NOT NULL ) ;
id: L'id du tag
tag : Le tag en question
articles_ids : Les ids des articles qui ont tag comme mot clé sous cette forme (1 2 14 26 ...)
Seulement je n'arrive pas au résultat escompté en procédant de cette manière:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 <? $donnes = mysql_query("SELECT keyword,article_id FROM article_master WHERE article_id<37"); while ($reponse = mysql_fetch_array($donnes)){ $chaine_tags = explode(",", $reponse['keyword']); $nbre_tags = count($chaine_tags); for($i= 0; $i < $nbre_tags; $i++) { $tags = trim($chaine_tags[$i]); $tags = NoAccent($tags); $remplace = array(' de ', ' le ', ' la ', ' pour ', ' un ', ' une ', ' d\'', ' l\'', ' avec '); $par = array(' ',' ',' ',' ',' ',' ',' ',' ',' '); $tags = str_replace($remplace, $par, $tags); $donnees1 = mysql_query("SELECT tag,articles_ids FROM tags WHERE tag=".$tags); $reponse1 = mysql_fetch_array($donnees1); if ($reponse1['tag'] == NULL) { mysql_query("INSERT INTO tags VALUES('', '".$tags."', '".$reponse['article_id']."')"); } if($reponse1['tag'] == $tags){ mysql_query("UPDATE tags SET articles_ids = '".$reponse1['articles_ids']." ".$reponse['article_id']."' WHERE tag=".$tags); } } ?>
en regardant dans ma table je m'aperçois que pour par exemple le tag "php" qui est lié aux articles 16 et 17, j'ai deux entrées :
id ---- tag ---- articles_ids
1 ----- php ---- 16
2 ----- php ---- 17
Alors que j'attends un truc du genre:
id ---- tag ---- articles_ids
1 ----- php ---- 16 17
Quelqu'un à la rescousse ?
Merci.
Partager