Forum Moderators: coopster
i was wondering if anyone knows a way of amending the code below so it is guaranteed to pull 3 different images without duplicating one.
for ( $count = 1; $count <= 3; $count += 1) {
$query = "SELECT * FROM blah ORDER BY RAND()";
$return = mysql_query($query);
$result = mysql_fetch_array($return);
echo'<img src="'.$result[1].'.jpg">';
}
any help appreciated!
$query = "SELECT * FROM blah ORDER BY RAND() LIMIT 3";
$return = mysql_query($query);
while ($result = mysql_fetch_array($return)) {
echo'<img src="'.$result[1].'.jpg">';
}
for ( $count = 1; $count <= 3; $count += 1) {
$query = "SELECT DISTINCT * FROM blah ORDER BY RAND()";
$return = mysql_query($query);
$result = mysql_fetch_array($return);
echo'<img src="'.$result[1].'.jpg">';
}
That would result in 3 separate calls to the database, unrelated to each other. Of course there's a possibility that the same record will be pulled twice.