Display random image within loop problem

From: Date: Mon, 05 Mar 2001 21:28:50 +0000
Subject: Display random image within loop problem
Groups: php.db 
Request: Send a blank email to php-db+get-7125@lists.php.net to get a copy of this message
I want to display a random image on a web page every 30 seconds. The problem I am having is that I get multiple images on the same web page all at once. It's not clearing the previous image and then displaying the new image. Must have something to do with the loop its in: <!-- Warning poor codinig listed below: --> <TABLE> <? mysql_connect("blah.com", "blah", "password"); $query = "SELECT * FROM graphicstable ORDER by ID"; $result = mysql_db_query("graphics", $query); $query = "SELECT COUNT(*) FROM graphicstable"; $numguests = mysql_query($query) or die("Select Failed!"); $numguest = mysql_fetch_array($numguests); // echo "Result is: $result"; // Begin Randomizer Function function random($max = 1) { static $startseed = 0; if (!$startseed) { $startseed = hexdec(uniqid(''))%getrandmax(); srand($startseed); } return ((rand()/getrandmax())*$max); } //end function if ($result) { $i = 0; $number = 3; //just to test number is total records in database IF ($number == 0) : PRINT "<CENTER><P>There were no records matching your query</CENTER>"; ELSEIF ($number > 0) : //PRINT "<CENTER><P>Search Results Returned: $number</CENTER><BR><BR>"; WHILE ($i < $number): // Assign variables within the loop // sleep (10); $bar =$numguest[0]; $foo = random($bar); // call random function to get a new random pic $record = mysql_result($result,$foo,"ID"); $cat = mysql_result($result,$foo,"category"); $name = mysql_result($result,$foo,"picture_name"); $rating = mysql_result($result,$foo,"rating"); // $name = mysql_result($result,$i,"name"); ?> <TR bgcolor="#000000" ><TH><small>Name:<? echo "$name"; ?> Record: <? echo "$record"; ?> Category: <? echo "$cat"; ?> Rating: <? echo "$rating"; ?>Total Records: <? echo $numguest[0]; ?> </small></TH></TR> <!-- 990000 is red --> <!-- <TR><TD> <? // echo "<img src=/graphics/uploads/$name width=$width height=$height><br>\n"; ?> </TD></TR> --> <TR bgcolor="#000000" ><TH>Random Number: <? echo "$foo"; ?> Record: <? echo "$record"; ?> Height= <? echo "$height"; ?> Width= <? echo "$width"; ?></TH></TR> </TR> <? //PRINT "<BR><BR>"; $i++; ENDWHILE; //PRINT "</CENTER>"; ENDIF; } ?> </TABLE>

« previous php.db (#7125) next »