[SOLVED] If Statement Problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

[SOLVED] If Statement Problem...

Post by sell-traffic »

Hi,

Not sure what's wrong with this code...

Code: Select all

<select name="select">
        <option value="0" <? if ($row_orderdetail['status'] = 0) { echo "selected"; } ?> >Pending</option>
        <option value="1" <? if ($row_orderdetail['status'] = 1) { echo "selected"; } ?> >Approved</option>
        <option value="2" <? if ($row_orderdetail['status'] = 2) { echo "selected"; } ?> >Waiting For User Response</option>
        <option value="3" <? if ($row_orderdetail['status'] = 3) { echo "selected"; } ?> >Fraudulent</option>
      </select>
The test value is 0 right now, so the "Pending" option should be selected, but this is the HTML code that results...

Code: Select all

&lt;select name="select"&gt;
        &lt;option value="0"  &gt;Pending&lt;/option&gt;
        &lt;option value="1" selected &gt;Approved&lt;/option&gt;
        &lt;option value="2" selected &gt;Waiting For User Response&lt;/option&gt;
        &lt;option value="3" selected &gt;Fraudulent&lt;/option&gt;
      &lt;/select&gt;
Thus, it always shows "Fraudulent".

Thanks,

Josh
Last edited by sell-traffic on Sat Sep 11, 2004 12:24 pm, edited 1 time in total.
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

RESOLVED

Post by sell-traffic »

Resolved with the following...

Code: Select all

<select name="statusbox" title="<?php echo $row_orderdetail['status']; ?>">
        <option value="0" <?php if (!(strcmp(0, $row_orderdetail['status']))) {echo "SELECTED";} ?>>Pending</option>
        <option value="1" <?php if (!(strcmp(1, $row_orderdetail['status']))) {echo "SELECTED";} ?>>Approved</option>
        <option value="2" <?php if (!(strcmp(2, $row_orderdetail['status']))) {echo "SELECTED";} ?>>Waiting For User Response</option>
        <option value="3" <?php if (!(strcmp(3, $row_orderdetail['status']))) {echo "SELECTED";} ?>>Fraudulent</option>
      </select>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

the matter was that you used wrong operator. '=' is assingment operator. to check for equality you would use '=='
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

Code isnt always like you would type it in real life. For more help on operators, look here
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

Post by sell-traffic »

Thanks everyone :)
Post Reply