Need help with a php script!

Discussion in 'PHP' started by demondestiny, Aug 10, 2010.

  1. #1
    I am making a php script that obtains a number limit from the user through html when the user clicks on the submit button it takes them to a php page that displays all numbers from 1 up to the number limit that the user chose and it will display odd or even next to each appropriate number.

    So if the user types in 4 it should display like this on the php page,

    1 odd
    2 even
    3 odd
    4 even

    I have already created the html part i just need help with the php, how would i go about doing this?

    Thanks.
     
    demondestiny, Aug 10, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    say your number from get or post is
    
    $num = $_GET['num']; // or $_POST['num']
    for($i = 1; $i <= $num; $i++)
    {
    echo $i, ' ', ($i%2==0 ? 'even' : 'odd'), "\n";
    }
    
    
    PHP:
     
    gapz101, Aug 10, 2010 IP
  3. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #3
    You could just use a simple switch if you only want to allow a certain amount of numbers.

    Glen
     
    HuggyEssex, Aug 10, 2010 IP