4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Randomising
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
GunstarHero
Junior WebHelper
Junior WebHelper


Joined: 15 Apr 2003
Posts: 35

PostPosted: Tue May 27, 2003 10:08 am (14 years, 6 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GunstarHeroSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Tue May 27, 2003 4:18 pm (14 years, 6 months ago) Reply with QuoteBack to Top

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

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
GunstarHero
Junior WebHelper
Junior WebHelper


Joined: 15 Apr 2003
Posts: 35

PostPosted: Tue May 27, 2003 5:11 pm (14 years, 6 months ago) Reply with QuoteBack to Top

Daniel, you beauty! Very Happy

It works just as I need it to.

Cheers for the help, it's always appreciated!

Anil
OfflineView User's ProfileFind all posts by GunstarHeroSend Personal Message
GunstarHero
Junior WebHelper
Junior WebHelper


Joined: 15 Apr 2003
Posts: 35

PostPosted: Thu May 29, 2003 8:18 pm (14 years, 6 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GunstarHeroSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




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.052044 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme