MySQL Forums
Forum List  »  PHP

MySQL RAND() QUERY NOT WORKING! PLZ HELP ASAP
Posted by: Parker England
Date: June 06, 2009 04:49PM

Ok what my code should do is select a random record and then get the image url stored in another column in that record, but instead it returns blank with nothing at all. Here is my code Keep in mind ball_id is the the feild that should be being selected and image is where the image url is stored with the ball_id.
<?php

$sqlStr = "SELECT * FROM ball ORDER BY RAND() LIMIT 0,1";

$res = mysql_query($sqlStr);

$ball = mysql_fetch_array($res);


$query = "SELECT * FROM ball WHERE ball_id='$ball'";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){

$image = $row['image'];
}
?>
<img src="<?php echo $image; ?>">

Options: ReplyQuote


Subject
Written By
Posted
MySQL RAND() QUERY NOT WORKING! PLZ HELP ASAP
June 06, 2009 04:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.