no12u Posted October 15, 2009 Share Posted October 15, 2009 I have some php code that picks randomly from mysql db when a certain level of points is reached and displays it on a page when accessed. The problem that I have is that when accessed by someone the information is randomly picked and changes each time it is accessed. How can I keep the same info each time it is accessed but will change again when a new level is reached. The data is stored in a table and cols on a mysql db. I am attaching the code. Thanks for the help in advance. //code below <?php $smldata = mysql_query("SELECT sml_reward FROM Rewards ORDER BY RAND() LIMIT 1;") or die(mysql_error()); while($smlinfo = mysql_fetch_array( $smldata )) { if ($total >49 and $total <74) { echo "<strong>You have achived 50 points and reached the 1st Reward level.<br> Your first reward is ",$smlinfo['sml_reward']; } else if ($total >74 and $total <99) { echo "<strong>You have achived 75 points and reached the 2nd Reward level.<br> Your Second reward is ",$smlinfo['sml_reward']; } else if ($total >124 and $total <149) { echo "<strong>You have achived 125 points and reached the 4th Reward level.<br> Your 125 Point Reward is ",$smlinfo['sml_reward']; } else if ($total >149 and $total <174) { echo "<strong>You have achived 150 points and reached the 5th Reward level.<br> Your 150 Point Reward is ",$smlinfo['sml_reward']; } else if ($total >174 and $total <199) { echo "<strong>You have achived 175 points and reached the 6th Reward level.<br> Your 175 Point Reward is ",$smlinfo['sml_reward']; } } $bigdata = mysql_query("SELECT big_reward FROM Rewards ORDER BY RAND() LIMIT 1;") or die(mysql_error()); while($biginfo = mysql_fetch_array( $bigdata )) { if ($total >99 and $total <124) echo "<strong>You have achived 100 points and reached the 3rd Reward level.<br> Your 100 Point Reward is ",$biginfo['big_reward']; if ($total >199 and $total <224) echo "<strong>You have achived 200 points and reached the 7th Reward level.<br> Your 200 Point Reward is ",$biginfo['big_reward']; } ?> Link to comment https://forums.phpfreaks.com/topic/177804-random-selection-and-viewing/ Share on other sites More sharing options...
physaux Posted October 15, 2009 Share Posted October 15, 2009 If i understand your question correctly, can't you just -have a "nexttotal" column in your users database. -Now each time you run this script, make it do the following: -If "nexttotal" is empty, set it to your lowest value, ex: 49$. -If "total>nexttotal", -select that random item, and attach it's ID to the users database. -update nexttotal to the higher level, ex:74$ Link to comment https://forums.phpfreaks.com/topic/177804-random-selection-and-viewing/#findComment-937613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.