|
Author |
Message |
GunstarHero
Junior WebHelper
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Tue May 27, 2003 10:08 am (20 years, 11 months ago) |
|
Hi,
I have a randomiser that randomly selects a number from a select query. Now I need to be able to loop this randomiser three times to give three separate results.
If it picks a number that it's already got, it should randomise again until it's unique, and do this three times in total.
Here's my random code:
Code: | <?php
$randomfilm = mysql_query ("SELECT dvdreviewID, dvdreviewdate, dvdreviewtitle, ratingoverall FROM dvdreview where ratingoverall >=7 and dvdreviewdate <= subdate(now(), interval 120 day);") or die (mysql_error() );
while ($row = mysql_fetch_array($randomfilm)) {
$row_array[] = $row ['dvdreviewID'];
}
$random_row = $row_array [rand(0, count ($row_array) -1 )];
echo ('<br>'."$random_row");
?> |
Any suggestions are most welcome!
Ta!
Anil |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue May 27, 2003 4:18 pm (20 years, 11 months ago) |
|
Code: | <?php
$randomfilm = mysql_query ("SELECT dvdreviewID, dvdreviewdate, dvdreviewtitle, ratingoverall FROM dvdreview where ratingoverall >=7 and dvdreviewdate <= subdate(now(), interval 120 day);") or die (mysql_error() );
while ($row = mysql_fetch_array($randomfilm)) {
$row_array[] = $row ['dvdreviewID'];
}
$random_row1 = $row_array [rand(0, count ($row_array) -1 )];
$random_row2 = $row_array [rand(0, count ($row_array) -1 )];
while ($random_row2 == $random_row1) {
$random_row2 = $row_array [rand(0, count ($row_array) -1 )];
}
$random_row3 = $row_array [rand(0, count ($row_array) -1 )];
while ($random_row3 == $random_row1 || $random_row3 == $random_row2) {
$random_row3 = $row_array [rand(0, count ($row_array) -1 )];
}
?> |
It most likely doesn't work, but it's a start |
________________________________
|
|
|
|
GunstarHero
Junior WebHelper
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Tue May 27, 2003 5:11 pm (20 years, 11 months ago) |
|
Daniel, you beauty!
It works just as I need it to.
Cheers for the help, it's always appreciated!
Anil |
|
|
|
|
GunstarHero
Junior WebHelper
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Thu May 29, 2003 8:18 pm (20 years, 11 months ago) |
|
Just to let you know that I built on the randomising code and made something meaningful for my website, Just DVD Reviews. You can see it in action on the front page in the Discs Revisted sidebar.
Thanks again for your help!
Anil |
|
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.140093 seconds :: 19 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |