simple php if statement

Discussion in 'PHP' started by jacka, May 23, 2007.

  1. #1
    Hi

    Can some one please tell me why the following if statement will done execute properly.
    I am fairly new to php.
    The purpose of the code snippet is to test if its first time the page loads and if it is , then to put the default values for startnumber and endnumber. The user then selects teh start and finish numbers from a list.


    many thx .
    :confused:



    <?php


    $startnumber=($_GET["start"]);
    $endnumber=($_GET["end"]);


    echo "startnumber= ".$startnumber;
    echo "endnumber= ".$endnumber;


    ?>
    html code....


    <?php



    if ($startnumber=0)
    {
    $startnumber=1;
    $endnumber=5;
    }



    for($i = $startnumber; $i <= $endnumber; $i++)
    {
    echo "<option ";
    if($row["qty"] == $i)
    {
    echo " SELECTED ";
    }
    echo ">" . $i . "</option>";
    }

    ?>
     
    jacka, May 23, 2007 IP
  2. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #2
    if ($startnumber=0)

    should be
    if ($startnumber==0)
     
    YIAM, May 23, 2007 IP
  3. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Yiam

    I thought that I had tried that, but obviously not.
    Great answer. many thx.
    :)
     
    jacka, May 23, 2007 IP
  4. sm9ai

    sm9ai Active Member

    Messages:
    746
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Yep remember

    = is assignment
    == is compare
     
    sm9ai, May 23, 2007 IP