|
Author |
Message |
GunstarHero
Junior WebHelper
![Junior WebHelper Junior WebHelper](images/rank_1.gif)
![](http://www.gunstarheroes.com/avatar/avatar.gif)
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Tue May 27, 2003 10:08 am (21 years ago) |
![Reply with Quote Reply with Quote](templates/4WebHelp2/images/lang_english/icon_quote.gif) ![Back to Top Back to Top](templates/4WebHelp2/images/icon_up.gif) |
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 |
|
|
![Offline](templates/4WebHelp2/images/offline.gif) ![View User's Profile View User's Profile](templates/4WebHelp2/images/lang_english/icon_profile.gif) ![Find all posts by GunstarHero Find all posts by GunstarHero](templates/4WebHelp2/images/lang_english/icon_search.gif) ![Send Personal Message Send Personal Message](templates/4WebHelp2/images/lang_english/icon_pm.gif) |
![](images/spacer.gif) |
Daniel
Team Member
![](images/rank_6.gif)
![](http://www.4webhelp.net/forums/images/daniel_avatar.php)
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue May 27, 2003 4:18 pm (21 years ago) |
![Reply with Quote Reply with Quote](templates/4WebHelp2/images/lang_english/icon_quote.gif) ![Back to Top Back to Top](templates/4WebHelp2/images/icon_up.gif) |
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 ![Wink](/forums/images/smilies/icon_wink.gif) |
________________________________
![Image Image](http://www.4webhelp.net/images/daniel_sig.gif) |
|
![Offline](templates/4WebHelp2/images/offline.gif) ![View User's Profile View User's Profile](templates/4WebHelp2/images/lang_english/icon_profile.gif) ![Find all posts by Daniel Find all posts by Daniel](templates/4WebHelp2/images/lang_english/icon_search.gif) ![Send Personal Message Send Personal Message](templates/4WebHelp2/images/lang_english/icon_pm.gif) |
![](images/spacer.gif) |
GunstarHero
Junior WebHelper
![Junior WebHelper Junior WebHelper](images/rank_1.gif)
![](http://www.gunstarheroes.com/avatar/avatar.gif)
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Tue May 27, 2003 5:11 pm (21 years ago) |
![Reply with Quote Reply with Quote](templates/4WebHelp2/images/lang_english/icon_quote.gif) ![Back to Top Back to Top](templates/4WebHelp2/images/icon_up.gif) |
Daniel, you beauty!
It works just as I need it to.
Cheers for the help, it's always appreciated!
Anil |
|
|
![Offline](templates/4WebHelp2/images/offline.gif) ![View User's Profile View User's Profile](templates/4WebHelp2/images/lang_english/icon_profile.gif) ![Find all posts by GunstarHero Find all posts by GunstarHero](templates/4WebHelp2/images/lang_english/icon_search.gif) ![Send Personal Message Send Personal Message](templates/4WebHelp2/images/lang_english/icon_pm.gif) |
![](images/spacer.gif) |
GunstarHero
Junior WebHelper
![Junior WebHelper Junior WebHelper](images/rank_1.gif)
![](http://www.gunstarheroes.com/avatar/avatar.gif)
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Thu May 29, 2003 8:18 pm (21 years ago) |
![Reply with Quote Reply with Quote](templates/4WebHelp2/images/lang_english/icon_quote.gif) ![Back to Top Back to Top](templates/4WebHelp2/images/icon_up.gif) |
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 |
|
|
![Offline](templates/4WebHelp2/images/offline.gif) ![View User's Profile View User's Profile](templates/4WebHelp2/images/lang_english/icon_profile.gif) ![Find all posts by GunstarHero Find all posts by GunstarHero](templates/4WebHelp2/images/lang_english/icon_search.gif) ![Send Personal Message Send Personal Message](templates/4WebHelp2/images/lang_english/icon_pm.gif) |
![](images/spacer.gif) |
|
|
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.129699 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |