Help - Search - Members - Calendar
Full Version: Help Creating 'loto Trace'
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
k.digennaro
A guy at work approached me the other day, knowing that I like to do things with computers and love to design and code things. He asked me to create him a program that would help trace his power ball lottery tickets. I told him I'd try since I'm always looking for projects and love to learn new things. I posted here regarding 'If' 'else' statements, the reason for that post was this program. The program would really have to parts to it.

The first part.
A way to submit 6 numbers. One number being the power ball. This information would then have to be stored for later use.

The second part.
A way to search through the information submitted in the first part. You would type is the winning numbers and if would tell you which ones matched and which ones didn't. And if the power ball matched it would highlight it or something to make it stand out.

I need help learning to turn this into the program I have in mind.

I've already created, with a little help, the if else statement that is the brains behind this program.
CODE

<?php

/**
* @DiGennaroDesigns
* @copyright 2008
*/

$x = 20;
$a = 5;
$b = 20;
$c = 13;
$d = 9;
$e = 5;
$f = 32;

$my_name = "someguy";

if ( $a == $x ) {
echo "Congratulations you're a winner!<br />";
}
else {
echo "Sorry this number wasn't a winner. Buy another ticket and try again!<br />"; //false
}
if ( $b == $x ) {
echo "Congratulations you're a winner!<br />";
}
else {
echo "Sorry this number wasn't a winner. Buy another ticket and try again!<br />"; //false
}
if ( $c == $x ) {
echo "Congratulations you're a winner!<br />";
}
else {
echo "Sorry this number wasn't a winner. Buy another ticket and try again!<br />"; //false
}
if ( $d == $x ) {
echo "Congratulations you're a winner!<br />";
}
else {
echo "Sorry this number wasn't a winner. Buy another ticket and try again!<br />"; //false
}
if ( $e == $x ) {
echo "Congratulations you're a winner!<br />";
}
else {
echo "Sorry this number wasn't a winner. Buy another ticket and try again!<br />"; //false
}
if ( $f == $x ) {
echo "Congratulations you're a winner!<br />";
}
else {
echo "Sorry this number wasn't a winner. Buy another ticket and try again!<br />"; //false
}


?>


Thanks,
Kevin DiGennaro
Andrew
Sorry I can't help right now, but just so you know, you have a useless line in your/my code.

$my_name = "someguy";

Delete that tongue.gif
I used a if else statement I found online to figure out the issue, and that was part of it. I took his code and slowly replaced parts of the if else statement with your parts and got it working. Forgot to delete that tongue.gif
L. Kaiserblazer
can you not do this using RapicPHP andrew?
Andrew
tongue.gif RapidPHP is basically a code editor, giving you helpful features to help YOU write the code. It doesn't have some kind of magical wizard that says "What do you need sir?" then I tell him "Give me a lotto program, pronto" then *poof* it's done
tongue.gif

Doesn't work like that I'm afraid.
k.digennaro
Thanks for the advice guys.

How can I make it so I have 6 "submit" boxes like below.


So that when I enter a number in the first box it assigns that number to variable "a" then the second box would assign to variable "b" etc.

Thanks,
Kevin DiGennaro
wozzym
i would have an external html file for that and then have it connect to the php file once it is submitted
Banjo
For the 6 boxes, use a input field or something and have 6 of them next to eachother all. Then when a button is pressed use post or get to assign them to variables.
Andrew
you'd have the html form something like this:
CODE
<form action="lotto.php" method="post">
<input type="text" name="one" />
<input type="text" name="two" />
<input type="text" name="three" />
<input type="text" name="four" />
<input type="text" name="five" />
<input type="text" name="six" />
<input type="submit" />
</form>


You can name them anything, I just did one through six... just because.

Now you notice when it submits its going to lotto.php, that can be changed, but it has to be the script where all your lotto functions are.
In the lotto.php you set your variables to look like this:
CODE
$a = $_POST["one"];
$b = $_POST["two"];
$c = $_POST["three"];
$d = $_POST["four"];
$e = $_POST["five"];
$f = $_POST["six"];


Somethin like that.
In your html form, you might have to do some coding to make them big like that and next to each other, I'm just giving you the basics.
Ed
QUOTE(k.digennaro @ Aug 30 2008, 01:25 PM) *
Thanks for the advice guys.

How can I make it so I have 6 "submit" boxes like below.


So that when I enter a number in the first box it assigns that number to variable "a" then the second box would assign to variable "b" etc.

Thanks,
Kevin DiGennaro


You could use a form array, something like:

CODE
<form action="" method="post">
  <input type="text" name="numbers[]" />
  <input type="text" name="numbers[]" />
  <input type="text" name="numbers[]" />
  <input type="text" name="numbers[]" />
  <input type="text" name="numbers[]" />
  <input type="text" name="numbers[]" />
  <input type="submit" value="Submit lottery numbers" />
</form>


Your numbers would be available within php, see here:
CODE
print_r($_POST['numbers']);


Don't forget to properly sanitize the values though, making sure you're only getting 6 numbers and nothing else. http://www.php.net/ctype-digit would be helpful here.

For storing the 6 numbers, I'd be inclined to opt for serializing and storing in a file, http://www.php.net/serialize http://www.php.net/file-put-contents

Checking within the numbers, you can unserialize the file contents and use http://www.php.net/in-array to see if it exists.

Hopefully this should get you on your way with writing it smile.gif.
Andrew
Haha Bread always has the better answer. (but isn't on IRC on the weekends when answers need answered :| )
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.