0

I have an issue where the if statement doesn't want to work, I'm not sure what is wrong. Regardless, it will always display the if condition. Initially, I have used a provisional code for the combo box which I'll edit later from the internet, to check if the if/else statement works, but it doesn't, and I can't see any reason why. Any clues? I'll be also adding a foreach statement into the select box, like this...

    <select>
    <?php
    foreach($bids as $bid)
    {
    ?>
        <option value="tbc">Some PHP code here</option>
    <?php
    }
    ?>
    </select>

This is the current full code I have:

<div class="frontpage_sidebar_header">Quick Flight Dispatch</div>
<div class="sidebox_content">
    <?php 
    if(!$bids)
    {
    ?>
        <table width="100%" style="padding: 5px; text-align: center;">
            <tr>
                <td>You haven't booked any flights</td>
            </tr>
        </table>
    <?php
    }
    else
    {
    ?>
        <select>
            <option value="volvo">Volvo</option>
            <option value="saab">Saab</option>
            <option value="mercedes">Mercedes</option>
            <option value="audi">Audi</option>
        </select>
    <?php
    }
    ?>      
</div>
4

3 回答 3

1
if(is_array($bids) && count($bids) > 0)
于 2013-01-25T11:50:06.503 回答
0

如果$bids是一个数组,您希望(!$bids)解决什么问题?

你应该这样写:

if (count($bids) === 0) {

因为这就是你的意思

于 2013-01-25T11:49:15.957 回答
0

尝试检查数组是否为空:if(count($bids) != 0) {}

于 2013-01-25T11:50:28.390 回答