I've contracted a simple tagging system,
My PHP page gets a string of tags, First it 'exlpode' them and then I use a foreach loop to find the tag id in the id-tagname table, once I found the tag id I place it in another table called articledtaged, where there two values, article id and tag id.
This is the code:
if (isset($_POST['tag'])&&!empty($_POST['tag'])){
$tag = $_POST['tag'];
$tagsarr = explode(",", $tag);
print_r ($tagsarr);
foreach($tagsarr as $key=>$row){
echo $row ;
$tagidquery = "SELECT id FROM tags WHERE tagname = '$row'";
$results = mysql_query($tagidquery);
$tagidarr = mysql_fetch_assoc($results);
$tagid = $tagidarr['id'];
echo $tagid;
$taginsertquery = "INSERT INTO tagedarticle (articleid,tagid) VALUES('$yourarticleid','$tagid')";
mysql_query($taginsertquery);
}
But the second part only works once,
For example, if I have 3 tags, "cool", "wonderful", "lame", each with its own id (lets say 4-6 for this example). The results will be
tagname tagid
cool 4
wonderful (empty)
lame (empty)
But why?!
please advice.