Reputation: 69
I have problem with mysql_fetch_array()
and while
loop. I have the query:
$tagsquery = mysql_query("SELECT `url` FROM `tags`, `mapa-tagow`, `statusy` WHERE `tags`.`id` = `mapa-tagow`.`tag-id` AND `statusy`.`id` = `mapa-tagow`.`article-id` AND `tags`.`tag` ='$tag' ORDER BY `url` ASC ") or die("ERROR: Tags doesn't exist.");
And results in while loop:
while($tags = mysql_fetch_array($tagsquery)) {
echo "<a href='tags.php?url=$url'>$url</a>, ";
}
When testing this query in PHPMyAdmin I have one more result than I get in PHP. I dont know why PHP always missing first result.
Upvotes: 1
Views: 1039
Reputation: 5201
A few possibilities:
while
loopOn a side note, you should build an array of your tag links, and then output them using implode... while(){ $tag_links[] = '<a href...';} print implode(', ', $tag_links);
Upvotes: 3
Reputation: 12244
You need to change your code to:
while($tags = mysql_fetch_array($tagsquery)) {
echo '<a href="tags.php?url='.$tags['url'].'">'.$tags['url'].'</a>, ';
}
Note that i took the opportunity to correct your tag output, there are many other ways to output HTML but this is easier to read in most cases.
If you can't spot the problem, i changed your $url to $tags['url'], so i output the URL from the $tags that you got from mysql_fetch_array()
Cheers
Upvotes: 1