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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    simple random problem

    Here is my code, its simple, I want php to generate a random number, then if its inbetween 1-5 echo a certain thing, or else if its 6-10 echo something else.

    PHP Code:
    <?
    $rand 
    rand(1,10)
    if(
    $rand == || || || || 5)
    {
    echo 
    "<h1>one thing</h1>";
    }

    if(
    $rand == || || || || 10)
    {
    echo 
    "<h1>other thing</h1>";
    }
    ?>
    all that happens now is a blank page
    thanks i'm dumb

  • #2
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    <?
    $rand = rand(1,10);
    if($rand == 1 || 2 || 3 || 4 || 5)
    {
    echo "<h1>one thing</h1>";
    }

    if($rand == 6 || 7 || 8 || 9 || 10)
    {
    echo "<h1>other thing</h1>";
    }
    ?>
    You missed a semi colon. But try this. This code can probably be optimized, though.

    PHP Code:
    <?php
    $rand 
    rand(1,10);

    if(
    $rand >= && $rand <= 5){ // If $rand is greater than or equal to 1 AND less than or equal to 5
        
    echo "Numbers 1 - 5!";
    }

    if(
    $rand >= && $rand <= 10){ // If $rand is greater than or equal to 6 AND less than or equal to 10
        
    echo "Numbers 6 - 10!";
    }
    ?>

  • Users who have thanked [vengeance] for this post:

    firecat318 (09-15-2009)

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks it worked


  •  

    Posting Permissions

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