Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lottery script help

    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");
    ?>

  • #2
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm going to look on PHP.NET for some help

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try adding a semi-colon ( ; ) after return() and after

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

    add

    }

    to make it

    PHP Code:
    <?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"); 
    }
    ?>
    Last edited by Nightfire; 03-29-2003 at 08:21 PM.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Chill... Don't expect help within minutes of posting when it's only YOU that was in this forum

  • #6
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know, but it doesn't work. There is an error on return()

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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

    PHP Code:
    if ((condition one) || (condition two) || (condition three)) 
    not

    PHP Code:
    if (condition one) || (condition two) || (condition three
    Hope that helps, if you have anymore questions, let us know - just remember to be patient.

    Duniyadnd

  • #8
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was patient, its just that the php was anoying me lol. Thanks for your help ayway.

  • #9
    New Coder
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Simpler?

    This is what I came up with. Simple enough?

    Code:
    <?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>");
    
    ?>

  • #10
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    it's ment to be
    PHP Code:
    return true


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •