Forum Moderators: coopster
I want to display widgets from the same category as links underneath the particular widget the visitor is viewing.
I'm using something similar this code:
SELECT * FROM thetable WHERE widget!='$widget' AND category='$category' LIMIT 4do {
printf("<p><a href=\"%s?widget=%s\">%s</a><br>-$s\n", $PHP_SELF, $myrow["widget"], $myrow["title"]);
printf("%s\n", $myrow["description"]);
} while ($myrow = mysql_fetch_array($result));
This does just want I want it to (displays 4 widgets from the same category), but the current widget is always displayed at the top of the list, despite my efforts to remove it (with WHERE widget!='$widget') and making 5 total entries rather than 4.
Can anyone see anything wrong with the code above that might cause this?
The way you have that written in your question, if the query produces four results, you're going to execute the loop code five times. The while condition runs after the first time through the loop.
Try calling
$myrow = mysql_fetch_array($result)
before the 'do' line as well to start it off. Otherwise, you're getting the $myrow variable that was previously set. It seems to have been previously set given that you're actually getting values on the first time through the loop.
;) glad it worked, I didn't do a great job explaining.