nclemale Posted August 15, 2011 Share Posted August 15, 2011 hi guys . been messing around with some codes and am trying to make a small code for my site so when they click on play it deducts site points off them and inserts it into a hourly jackpot that is won randomly .first off is i cant manage to carry the jackpot to the winning user .at present i have it set at 1000 points which works fine . this is the code that when they clck play $lot = mysql_fetch_array(mysql_query("SELECT jackpot FROM lotto ")); $res=mysql_query("UPDATE lotto SET jackpot='".($lot[0]+50)."'"); $res=mysql_query("UPDATE users SET lotto='1' WHERE id='".$uid."'"); $ugpl = mysql_fetch_array(mysql_query("SELECT plusses FROM users WHERE id='".$uid."'")); $ugpl = $ugpl[0] - 50; mysql_query("UPDATE users SET plusses='".$ugpl."' WHERE id='".$uid."'"); if($res){ echo "<img src=\"../images/ok.gif\" alt=\"o\"/>Entered lotto successfully<br/>"; }else{ echo "<img src=\"../images/notok.gif\" alt=\"x\"/>Error<br/>"; } and this is the winning code for when a user is chosen . $rpgd = mysql_query("SELECT id, lotto FROM users ORDER by lotto DESC LIMIT 1"); while($rpgds=mysql_fetch_array($rpgd)) { $winner =$rpgds[0]; $winner2 =$rpgds[1]; } $unick2 = getnick_uid($winner); mysql_query("UPDATE users SET plusses=plusses+'1000' WHERE id='".$winner."'"); mysql_query("UPDATE users SET lotto='0'"); mysql_query("UPDATE lotto SET jackpot='0'"); echo"$unick2 has won the jackpot "; as you can see the line that has plusses=plusses+'1000' is the part i need to get right. once i have this sorted i will need help with the time part of it. thanks Quote Link to comment https://forums.phpfreaks.com/topic/244832-carrying-an-amount-to-the-next-code-stage/ Share on other sites More sharing options...
nclemale Posted August 15, 2011 Author Share Posted August 15, 2011 ok after trying a few more things i finally sussed it so it carries the jackpot to the user that wins . all i did is this $jack = mysql_fetch_array(mysql_query("SELECT jackpot FROM lotto ")); mysql_query("UPDATE users SET plusses=plusses+'$jack[0]' WHERE id='".$winner."'"); simple yes but i am just learning. ok is there a way i can add time coding in this so lets say it all gets reset every hour and it randomly picks a winner on its own. ?? Quote Link to comment https://forums.phpfreaks.com/topic/244832-carrying-an-amount-to-the-next-code-stage/#findComment-1257740 Share on other sites More sharing options...
xyph Posted August 15, 2011 Share Posted August 15, 2011 Look into Cron jobs (unix) or Scheduled Tasks (windows) for that. Quote Link to comment https://forums.phpfreaks.com/topic/244832-carrying-an-amount-to-the-next-code-stage/#findComment-1257742 Share on other sites More sharing options...
nclemale Posted August 15, 2011 Author Share Posted August 15, 2011 thats sounds complicated .could i not just make a function in my main file that runs all my other parts of site . and if so where would i even start. ? Quote Link to comment https://forums.phpfreaks.com/topic/244832-carrying-an-amount-to-the-next-code-stage/#findComment-1257748 Share on other sites More sharing options...
xyph Posted August 15, 2011 Share Posted August 15, 2011 You could. I'd start with a function that checks when the last lotto was run, then check if an hour has passed since then. Cron jobs are quite simple, and probably the easiest way to accomplish this. Quote Link to comment https://forums.phpfreaks.com/topic/244832-carrying-an-amount-to-the-next-code-stage/#findComment-1257796 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.