...

View Full Version : Lottery script help



LRmaster
03-29-2003, 08:12 PM
When I uploaded it and tried it out, it said parse error on line 14, the one with all the ORs on. I figure its just because there is a lot of ORs, but can someone help me get it right? Theres proberly a script what can make where if any of the numbers are equal, restart. Also I need help to see if the return() actually restarts the whole script again. My lottery script is:

<?php
$high = 1;
$low = 49;
print ("Your recommended lottery number for this week is:");

$Number1 = rand($high,$low);
$Number2 = rand($high,$low);
$Number3 = rand($high,$low);
$Number4 = rand($high,$low);
$Number5 = rand($high,$low);
$Number6 = rand($high,$low);

if ($Number1 == $Number2) OR ($Number1 == $Number3) OR ($Number1 == $Number4) OR ($Number1 == $Number5) OR ($Number1 == $Number6) OR ($Number2 == $Number3) OR ($Number2 == $Number4) OR ($Number2 == $Number5) OR ($Number2 == $Number6) OR ($Number3 == $Number4) OR ($Number3 == $Number5) OR ($Number3 == $Number6) OR ($Number4 == $Number5) OR ($Number4 == $Number6) OR ($Number5 == $Number6)
{
return()
}
else {
print ("$Number1, $Number2, $Number3, $Number4, $Number5, $Number6");
?>

LRmaster
03-29-2003, 08:17 PM
All right I got it fixed, ut there is now an error on line 16 where the return() is. Maybe its not the correct code.

LRmaster
03-29-2003, 08:18 PM
:mad: I'm going to look on PHP.NET for some help

Nightfire
03-29-2003, 08:19 PM
Try adding a semi-colon ( ; ) after return() and after

print ("$Number1, $Number2, $Number3, $Number4, $Number5, $Number6");

add

}

to make it



<?php
$high = "1";
$low = "49";
print ("Your recommended lottery number for this week is:");

$Number1 = rand($high,$low);
$Number2 = rand($high,$low);
$Number3 = rand($high,$low);
$Number4 = rand($high,$low);
$Number5 = rand($high,$low);
$Number6 = rand($high,$low);

if ($Number1 == $Number2) || ($Number1 == $Number3) || ($Number1 == $Number4) || ($Number1 == $Number5) || ($Number1 == $Number6) || ($Number2 == $Number3) || ($Number2 == $Number4) || ($Number2 == $Number5) || ($Number2 == $Number6) || ($Number3 == $Number4) || ($Number3 == $Number5) || ($Number3 == $Number6) || ($Number4 == $Number5) || ($Number4 == $Number6) || ($Number5 == $Number6)
{
return();
}
else {
print ("$Number1, $Number2, $Number3, $Number4, $Number5, $Number6");
}
?>

Nightfire
03-29-2003, 08:20 PM
Chill... :rolleyes: Don't expect help within minutes of posting when it's only YOU that was in this forum

LRmaster
03-29-2003, 08:37 PM
I know, but it doesn't work. There is an error on return()

duniyadnd
03-30-2003, 09:23 PM
you have to return to something else that calls it (another function), and looking at your program, it doesn't seem that you have any functions.

Here is an example, you just have to change the output, I changed the coding around so that you will actually look at it and get what I'm trying to get at.

functions are in classes, we created an object that called the class, and then the object looks at the function.



<?php

//define object
$t = new somesome;
//object calls function
$t->somesome();

//class
class somesome{

//constructor
function somesome()
{

$high = "1";
$low = "49";

//added this
$trueorfalse = 0;



$Number1 = rand($high,$low);
$Number2 = rand($high,$low);
$Number3 = rand($high,$low);
$Number4 = rand($high,$low);
$Number5 = rand($high,$low);
$Number6 = rand($high,$low);


/*made it into an array so you can always add new Numbers and don't have to worry about future "if" statements*/
$array = array($Number1, $Number2, $Number3, $Number4, $Number5, $Number6);
$len = count($array);

for ($i=0;$i<$len;$i++)
{
for ($j=0;$j<$len;$j++)
{
if ($array[$i]==$array[$j])
{
$trueorfalse = 1;
}
}
}
if ($trueorfalse == 1)
{
/*it will keep going back to the function in this class until you get the output you want*/
return $this->somesome();
}

else if ($trueorfalse == 0)
{
echo "Your recommended lottery number for this week is: ";
echo "Groovy"; /* you'll have to change this to the output you want*/
}//end else

}//end function
}//end class
?>



In simple english, the reason your return wasn't working was because the program didn't know what to return to. You have to define where to go if you didn't specify where you called it from.

Also, the previous errors targetted by fellow helpers was also true ";" and ending your else statement with "}" would always help. Also, make sure you have your "if" statement as one statement



if ((condition one) || (condition two) || (condition three))


not



if (condition one) || (condition two) || (condition three)


Hope that helps, if you have anymore questions, let us know - just remember to be patient. ;)

Duniyadnd

LRmaster
03-31-2003, 03:23 PM
I was patient, its just that the php was anoying me lol. Thanks for your help ayway.

dsavage666
08-31-2006, 08:49 PM
This is what I came up with. Simple enough?


<?php

global $Number1,$Number2,$Number3,$Number4,$Number5,$Number6;

$high = 1;
$low = 49;

print ("<center>Your lucky lottery numbers are:<br>");

while (($Number1 == $Number2) || ($Number1 == $Number3) || ($Number1 == $Number4) || ($Number1 == $Number5) || ($Number1 == $Number6) || ($Number2 == $Number3) || ($Number2 == $Number4) || ($Number2 == $Number5) || ($Number2 == $Number6) || ($Number3 == $Number4) || ($Number3 == $Number5) || ($Number3 == $Number6) || ($Number4 == $Number5) || ($Number4 == $Number6) || ($Number5 == $Number6)):

$Number1 = rand($high,$low);
$Number2 = rand($high,$low);
$Number3 = rand($high,$low);
$Number4 = rand($high,$low);
$Number5 = rand($high,$low);
$Number6 = rand($high,$low);

endwhile;

print ("<b>$Number1, $Number2, $Number3, $Number4, $Number5, $Number6</b></center>");

?>

Lee Stevens
08-31-2006, 08:55 PM
it's ment to be
return true;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum