Help me correct this code

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

9 replies · 477 views · started 14 years ago · 1 min read

4 participants
Wintch Developer · 68 posts #1

Please anytime i want to display my members photo like 2 or 3 it always giving me more that what i wanted. Eg. I want to display 3 userz photo in random, it will display more than 50 images. Pls whats wrong.

<?php 
 $usera=$db->get_row("SELECT * FROM b_users ORDER BY rand() DESC LIMIT 0,3");
if($usera)
{
foreach($usera as $userd8)
{
if (!empty($userd8->avatar)) 
print "<tr><td><div class=\"advert\"><img src=\"".$config->url."/avatars/".$userd8->avatar."\"
width=\"70\" height=\"70\"> ";
//else, print gravatar
else if($userd8->sex == "female") echo "<img src=\"".$config->url."/avatars/avatarf.png\" width=\"70\" height=\"70\"></img>"; else echo "<img src=\"".$config->url."/avatars/avatarm.png\" width=\"70\" height=\"70\"></img>";  
}
}
?>
something else Fellow · 2,296 posts #2
 $usera=$db->get_row("SELECT * FROM b_users ORDER BY rand() LIMIT 3");
Wintch Developer · 68 posts #3

thanx man. but still not working... it still giving me multiple photos

Devil223 Junior · 34 posts #4
 $usera=$db->get_row("SELECT * FROM b_users ORDER BY RAND() LIMIT 0,3");  
Wintch Developer · 68 posts #5

thanx let me try...

something else Fellow · 2,296 posts #6

Devil223 wrote:

 $usera=$db->get_row("SELECT * FROM b_users ORDER BY RAND() LIMIT 0,3");  

sorry i edited it before you tried it lol should be limit 3 not 0, 3

Wintch Developer · 68 posts #7

hmm, try both bt still not working

arnage Lead · 811 posts #8

What are the symptoms? Try to remove foreach loop, in get_row should be while() already.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Wintch Developer · 68 posts #9

Can u give me da sample code using the while() loop

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close