Jump to content
MakeWebGames

lottery cron


peterisgb

Recommended Posts

Hi i'm trying to make a lottery cron for my lotto system i am making,

i aint very good at cron files so i was wondering if i could get help with it.

Below is what i have done so far:

<?php
include "config.php";
global $_CONFIG;
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;

$db->query("TRUNCATE TABLE lottolast;");

$num1=rand(1, 15);
$num2=rand(1, 15);
$num3=rand(1, 15);
$num4=rand(1, 15);
$num5=rand(1, 15);
$uc = $db->query("SELECT * FROM lotto");
$cl = $db->fetch_row($uc);
$pc = $db->query("SELECT lotto1 FROM users WHERE userid={$cl['userid']}");
$pl = $db->fetch_row($pc);
if($cl['lottery1'] == $num1) { $cor1="1000000"; } else { $cor1="0"; }
if($cl['lottery2'] == $num2) { $cor2="1000000"; } else { $cor2="0"; }
if($cl['lottery3'] == $num3) { $cor3="1000000"; } else { $cor3="0"; }
if($cl['lottery4'] == $num4) { $cor4="1000000"; } else { $cor4="0"; }
if($cl['lottery5'] == $num5) { $cor5="1000000"; } else { $cor5="0"; }
if($pl['lotto1'] == 1) 
{ 
$prize=$cor1+$cor2+$cor3+$cor4+$cor5;
} else {
$prize=0;
}
$db->query("UPDATE users SET bankmoney=bankmoney+$prize WHERE userid={$cl['userid']}");
$db->query("UPDATE users SET lotto1=0");
$db->query("INSERT INTO lottolast SET lotto1=$num1, lotto2=$num2, lotto3=$num3, lotto4=$num4, lotto5=$num5");

print "
Prize: $prize <br />
Number 1: $num1 <br />
Number 2: $num2 <br />
Number 3: $num3 <br />
Number 4: $num4 <br />
Number 5: $num5 <br />
Users {$cl['userid']} <br />
";

?>

 

I have also attached lotto.php. this does work.

<?php
include "globals.php";
switch($_GET['action'])
{
case 'play2': do_play(); break;
case 'play': conf_play(); break;
default: prefs_home(); break;
}
function prefs_home()
{
global $db,$ir,$c,$userid,$h;
$uc = $db->query("SELECT * FROM lotto WHERE userid=$userid");
$cl = $db->fetch_row($uc);
$dc = $db->query("SELECT * FROM lottolast");
$ll = $db->fetch_row($dc);
$num1=rand(1, 15);
$num2=rand(1, 15);
$num3=rand(1, 15);
$num4=rand(1, 15);
$num5=rand(1, 15);
print "<h3>Lottery HQ</h3>
You can enter each set once.
<table width='75%'>
<tr>
<td><b>Set</b></td>
<td><b>Prize</b><small> (per correct number)</small></td>
<td><b>Ticket Cost</b></td>
<td><b>Action</b></td>
</tr>

<tr>
<td>1</td>
<td>$1,000,000</td>
<td>$5,000</td>
<td>";
if($ir['lotto1'] == 1) { 
print "NONE"; } else { 
print "<a href='lotto?action=play'>Play Set 1</a>"; }
print "
</td>
</tr>";
if($ir['lotto1'] == 1) {
print "
<tr>
<td align='center' colspan='4'>Your Numbers are.
{$cl['lottery1']}, {$cl['lottery2']}, {$cl['lottery3']}, {$cl['lottery4']}, {$cl['lottery5']}";
} print "
</td></tr>
</table>
<br /><br />
Last Weeks lotto Numbers <br />
{$ll['lotto1']} , {$ll['lotto2']} , {$ll['lotto3']} , {$ll['lotto4']} , {$ll['lotto5']}.";
}



function conf_play()
{
global $ir,$c,$userid,$h;
if($ir['lotto1'] == 1) {
die ("You have already entered this lotto set.<a href='lotto'>Lotto Home</a>");
}
if($ir['money'] <= 4999) {
die ("You Either do not have cash in hand or you dont have enough to buy a ticket.<a href='lotto'>Lotto Home</a>");
}
print "
<div class='form_description'>
<h2>Pick one number from each line</h2>
</div>    
<form action='lotto?action=play2' method='post'>
<table width='100%'>
<tr><td align='center'>
<hr />
</td></tr>
<tr><td align='center'>
   <INPUT type='radio' name='lottery1' value='1'>1.
   <INPUT type='radio' name='lottery1' value='2'>2.
   <INPUT type='radio' name='lottery1' value='3'>3.
   <INPUT type='radio' name='lottery1' value='4'>4.
   <INPUT type='radio' name='lottery1' value='5'>5.
   <INPUT type='radio' name='lottery1' value='6'>6.
   <INPUT type='radio' name='lottery1' value='7'>7.
   <INPUT type='radio' name='lottery1' value='8'>8.
   <INPUT type='radio' name='lottery1' value='9'>9.
   <INPUT type='radio' name='lottery1' value='10'>10.
   <INPUT type='radio' name='lottery1' value='11'>11.
   <INPUT type='radio' name='lottery1' value='12'>12.
   <INPUT type='radio' name='lottery1' value='13'>13.
   <INPUT type='radio' name='lottery1' value='14'>14.
   <INPUT type='radio' name='lottery1' value='15'>15.
</td></tr>
<tr><td>
<hr />
</td></tr>
<tr><td align='center'>
   <INPUT type='radio' name='lottery2' value='1'>1.
   <INPUT type='radio' name='lottery2' value='2'>2.
   <INPUT type='radio' name='lottery2' value='3'>3.
   <INPUT type='radio' name='lottery2' value='4'>4.
   <INPUT type='radio' name='lottery2' value='5'>5.
   <INPUT type='radio' name='lottery2' value='6'>6.
   <INPUT type='radio' name='lottery2' value='7'>7.
   <INPUT type='radio' name='lottery2' value='8'>8.
   <INPUT type='radio' name='lottery2' value='9'>9.
   <INPUT type='radio' name='lottery2' value='10'>10.
   <INPUT type='radio' name='lottery2' value='11'>11.
   <INPUT type='radio' name='lottery2' value='12'>12.
   <INPUT type='radio' name='lottery2' value='13'>13.
   <INPUT type='radio' name='lottery2' value='14'>14.
   <INPUT type='radio' name='lottery2' value='15'>15.
</td></tr>
<tr><td>
<hr />
</td></tr>
<tr><td align='center'>
   <INPUT type='radio' name='lottery3' value='1'>1.
   <INPUT type='radio' name='lottery3' value='2'>2.
   <INPUT type='radio' name='lottery3' value='3'>3.
   <INPUT type='radio' name='lottery3' value='4'>4.
   <INPUT type='radio' name='lottery3' value='5'>5.
   <INPUT type='radio' name='lottery3' value='6'>6.
   <INPUT type='radio' name='lottery3' value='7'>7.
   <INPUT type='radio' name='lottery3' value='8'>8.
   <INPUT type='radio' name='lottery3' value='9'>9.
   <INPUT type='radio' name='lottery3' value='10'>10.
   <INPUT type='radio' name='lottery3' value='11'>11.
   <INPUT type='radio' name='lottery3' value='12'>12.
   <INPUT type='radio' name='lottery3' value='13'>13.
   <INPUT type='radio' name='lottery3' value='14'>14.
   <INPUT type='radio' name='lottery3' value='15'>15.
</td></tr>
<tr><td>
<hr />
</td></tr>
<tr><td align='center'>
   <INPUT type='radio' name='lottery4' value='1'>1.
   <INPUT type='radio' name='lottery4' value='2'>2.
   <INPUT type='radio' name='lottery4' value='3'>3.
   <INPUT type='radio' name='lottery4' value='4'>4.
   <INPUT type='radio' name='lottery4' value='5'>5.
   <INPUT type='radio' name='lottery4' value='6'>6.
   <INPUT type='radio' name='lottery4' value='7'>7.
   <INPUT type='radio' name='lottery4' value='8'>8.
   <INPUT type='radio' name='lottery4' value='9'>9.
   <INPUT type='radio' name='lottery4' value='10'>10.
   <INPUT type='radio' name='lottery4' value='11'>11.
   <INPUT type='radio' name='lottery4' value='12'>12.
   <INPUT type='radio' name='lottery4' value='13'>13.
   <INPUT type='radio' name='lottery4' value='14'>14.
   <INPUT type='radio' name='lottery4' value='15'>15.
</td></tr>
<tr><td>
<hr />
</td></tr>
<tr><td align='center'>
   <INPUT type='radio' name='lottery5' value='1'>1.
   <INPUT type='radio' name='lottery5' value='2'>2.
   <INPUT type='radio' name='lottery5' value='3'>3.
   <INPUT type='radio' name='lottery5' value='4'>4.
   <INPUT type='radio' name='lottery5' value='5'>5.
   <INPUT type='radio' name='lottery5' value='6'>6.
   <INPUT type='radio' name='lottery5' value='7'>7.
   <INPUT type='radio' name='lottery5' value='8'>8.
   <INPUT type='radio' name='lottery5' value='9'>9.
   <INPUT type='radio' name='lottery5' value='10'>10.
   <INPUT type='radio' name='lottery5' value='11'>11.
   <INPUT type='radio' name='lottery5' value='12'>12.
   <INPUT type='radio' name='lottery5' value='13'>13.
   <INPUT type='radio' name='lottery5' value='14'>14.
   <INPUT type='radio' name='lottery5' value='15'>15.
</td></tr>
<tr><td>
<hr />
</td></tr>
</table>
<input type='submit' value='Play these numbers' class='loginbox' /></form>
<a href='lotto'>Lotto Home</a>
";
}
function do_play()
{
global $db,$ir,$c,$userid,$h;
$db->query("UPDATE lotto SET
lottery1='{$_POST['lottery1']}', 
lottery2='{$_POST['lottery2']}', 
lottery3='{$_POST['lottery3']}', 
lottery4='{$_POST['lottery4']}',
lottery5='{$_POST['lottery5']}'");
$db->query("UPDATE users SET lotto1='1', money=money-5000 WHERE userid=$userid");
print "Your Numbers Are <h3>
{$_POST['lottery1']}, {$_POST['lottery2']}, {$_POST['lottery3']}, {$_POST['lottery4']}, {$_POST['lottery5']}.</h3>
Good Luck.
<a href='lotto'>Back</a>";
}


$h->endpage();
?>
Edited by peterisgb
Updated Current Revision
Link to comment
Share on other sites

Hi i'm trying to make a lottery cron for my lotto system i am making,

i aint very good at cron files so i was wondering if i could get help with it.

Below is what i have done so far:

I'm not even going to look at the code until you say what part are you specifically stuck on?, also, just paste the code that is relevant to the part you're stuck on.

Link to comment
Share on other sites

okay the first script ... looks to me you are missing some ( parenthesis ) around stuff like this $prize=$cor1+$cor2+$cor3+$cor4+$cor5;

I think needs to be

$prize=($cor1+$cor2+$cor3+$cor4+$cor5); but i might be wrong. Also i think you need more quotes in your SQL around table name and your column names, single quotes.

so you have them pick numbers in the script and it updates their users table with the lotto numbers then the cron runs and clears the current lottery numbers and checks user table(s) for any matching picked numbers and rewards each person with their lottery winnings?

maybe... ??

Link to comment
Share on other sites

hm,, well this system kinda works already, but not quite got the right user selection really. my database is like this:

users database there is 'lotto1' which is 1 for got ticket and 0 for not.

Meanwhile into its own table lotto and lottodraw. lotto is where the userid and lotto numbers go and lottodraw is where the Last numbers picked get entered into.

This system does work now, just the user selection that i ain't sure.

It seems to draw the lotto and credit me fine when i get correct number and x2 prize for 2 or matching numbers.

After coding mccodes for years i still ain't very good at it.

I have updated the Main post with the latest update.

P.S, Sorry for my grammar and stuff, my English writing was never any good.

Edited by peterisgb
Link to comment
Share on other sites

hm,, well this system kinda works already, but not quite got the right user selection really. my database is like this:

users database there is 'lotto1' which is 1 for got ticket and 0 for not.

Meanwhile into its own table lotto and lottodraw. lotto is where the userid and lotto numbers go and lottodraw is where the Last numbers picked get entered into.

This system does work now, just the user selection that i ain't sure.

It seems to draw the lotto and credit me fine when i get correct number and x2 prize for 2 or matching numbers.

After coding mccodes for years i still ain't very good at it.

I have updated the Main post with the latest update.

P.S, Sorry for my grammar and stuff, my English writing was never any good.

maybe in your cron you need a foreach($[uid] as user){ do cron } type of thing for user selection?? is this your problem or what is supposed to happen that isnt?

Link to comment
Share on other sites

ok i think i found the error

 

$db->query("INSERT INTO `lottolast` SET
       `lotto1` = '$num1', `lotto2` = '$num2', `lotto3` = '$num3', `lotto4` = '$num4', `lotto5` = '$num5'");

 

	

   <?php
   include(__DIR__."/config.php");
   global $_CONFIG;
   define("MONO_ON", 1);
   require "class/class_db_{$_CONFIG['driver']}.php";
   $db=new database;
   $db->configure($_CONFIG['hostname'],
   $_CONFIG['username'],
   $_CONFIG['password'],
   $_CONFIG['database'],
   $_CONFIG['persistent']);
   $db->connect();
   $c=$db->connection_id;

   $db->query("TRUNCATE TABLE lottolast;");

   $num1 = rand(1, 15);
   $num2 = rand(1, 15);
   $num3 = rand(1, 15);
   $num4 = rand(1, 15);
   $num5 = rand(1, 15);
   $uc = $db->query("SELECT * FROM `lotto`");
   while($cl = $db->fetch_row($uc))
   {
           $pc = $db->query("SELECT `lotto1` FROM `users` WHERE `userid` = {$cl['userid']}");
           $pl = $db->fetch_row($pc);
           if($cl['lottery1'] == $num1) { $cor1="1000000"; } else { $cor1="0"; }
           if($cl['lottery2'] == $num2) { $cor2="1000000"; } else { $cor2="0"; }
           if($cl['lottery3'] == $num3) { $cor3="1000000"; } else { $cor3="0"; }
           if($cl['lottery4'] == $num4) { $cor4="1000000"; } else { $cor4="0"; }
           if($cl['lottery5'] == $num5) { $cor5="1000000"; } else { $cor5="0"; }
           if($pl['lotto1'] == 1)
           {
                   $prize = $cor1+$cor2+$cor3+$cor4+$cor5;
           }
           else
           {
                   $prize=0;
           }
           $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` + $prize WHERE `userid` = {$cl['userid']}");
           $db->query("UPDATE `users` SET `lotto1` = '0'");
           $db->query("INSERT INTO `lottolast` SET
           `lotto1` = '$num1', `lotto2` = '$num2', `lotto3` = '$num3', `lotto4` = '$num4', `lotto5` = '$num5'");
   }
   print "
   Prize: $prize
   Number 1: $num1
   Number 2: $num2
   Number 3: $num3
   Number 4: $num4
   Number 5: $num5
   Users {$cl['userid']}
   ";

   ?>
Link to comment
Share on other sites

ok i think i found the error

 

$db->query("INSERT INTO `lottolast` SET
       `lotto1` = '$num1', `lotto2` = '$num2', `lotto3` = '$num3', `lotto4` = '$num4', `lotto5` = '$num5'");

 

	

   <?php
   include(__DIR__."/config.php");
   global $_CONFIG;
   define("MONO_ON", 1);
   require "class/class_db_{$_CONFIG['driver']}.php";
   $db=new database;
   $db->configure($_CONFIG['hostname'],
   $_CONFIG['username'],
   $_CONFIG['password'],
   $_CONFIG['database'],
   $_CONFIG['persistent']);
   $db->connect();
   $c=$db->connection_id;

   $db->query("TRUNCATE TABLE lottolast;");

   $num1 = rand(1, 15);
   $num2 = rand(1, 15);
   $num3 = rand(1, 15);
   $num4 = rand(1, 15);
   $num5 = rand(1, 15);
   $uc = $db->query("SELECT * FROM `lotto`");
   while($cl = $db->fetch_row($uc))
   {
           $pc = $db->query("SELECT `lotto1` FROM `users` WHERE `userid` = {$cl['userid']}");
           $pl = $db->fetch_row($pc);
           if($cl['lottery1'] == $num1) { $cor1="1000000"; } else { $cor1="0"; }
           if($cl['lottery2'] == $num2) { $cor2="1000000"; } else { $cor2="0"; }
           if($cl['lottery3'] == $num3) { $cor3="1000000"; } else { $cor3="0"; }
           if($cl['lottery4'] == $num4) { $cor4="1000000"; } else { $cor4="0"; }
           if($cl['lottery5'] == $num5) { $cor5="1000000"; } else { $cor5="0"; }
           if($pl['lotto1'] == 1)
           {
                   $prize = $cor1+$cor2+$cor3+$cor4+$cor5;
           }
           else
           {
                   $prize=0;
           }
           $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` + $prize WHERE `userid` = {$cl['userid']}");
           $db->query("UPDATE `users` SET `lotto1` = '0'");
           $db->query("INSERT INTO `lottolast` SET
           `lotto1` = '$num1', `lotto2` = '$num2', `lotto3` = '$num3', `lotto4` = '$num4', `lotto5` = '$num5'");
   }
   print "
   Prize: $prize
   Number 1: $num1
   Number 2: $num2
   Number 3: $num3
   Number 4: $num4
   Number 5: $num5
   Users {$cl['userid']}
   ";

   ?>

As said previously that this does work 100% as it is now, just not the user functions right.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...