How to echo a different variable value each pass in a WHILE loop in (PHP)?
May 10th, 2010
This script echos 70 variables values named $NAME from the database randomly. But it shows the same random name that was picked and echoes the same name 70 times e.g. TONYTONYTONY…. Is it possible to echo 70 different NAMES using a while loop so that one name never repeats itself twice. E.g. TONY ROBERT CHARLEY JAMES CHRIS. You get the idea.
This is the script i used that echos 70 of the same name:
$query = “SELECT * FROM tablename ORDER BY rand() LIMIT 70″;
$result = mysql_query($query)
or die (“crap”);
$num = mysql_num_rows($result);
$row = mysql_fetch_array($result);
extract($row);
while ($row = mysql_fetch_array($result))
{
echo “$NAME”;
}
Can you edit this to make it echo a different name each pass of the while loop and never repeat more than once.
Thanx, any questions just ask. I need help bad lol.

Twitter
2 Comments