sayen Posted October 14, 2011 Share Posted October 14, 2011 15 rows selected from the table. I want to randomly display an ad between them. Here's the code: $count = 1; (mysql select rows) $number = rand (1,15); if ($count == $number) { echo 'ad code '; } $count++; I want the ad to be displayed only once and in the above code, depending on the generated number by rand() matching the $number the ads will be displayed more times. How can I limit this only to one? Quote Link to comment https://forums.phpfreaks.com/topic/249148-randomly-display-with-counting/ Share on other sites More sharing options...
requinix Posted October 14, 2011 Share Posted October 14, 2011 Pick your $number before the loop. Quote Link to comment https://forums.phpfreaks.com/topic/249148-randomly-display-with-counting/#findComment-1279484 Share on other sites More sharing options...
sayen Posted October 14, 2011 Author Share Posted October 14, 2011 I knew that it was a simple thing. Works like a charm, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/249148-randomly-display-with-counting/#findComment-1279489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.