2011-02-15 03:49
浏览 48


So I have this problem, which I don't see how it's happening. Basically I have 2 arrays one of which has a list of apparatus and the other just has one apparatus that the user can operate. I want to have a dropdown list of all the apparatus avliable, but the default value that is selected is the one that they can operate (They can only operate one at a time) Here is the code, and I have an if statement to check if the user can operate it and selected = "selected" but that doesn't seem to be working (In firefox)... Any help would be great.


                            foreach ($apparatuslist as $apparatus):?>
                            <option value="<?php echo $apparatus['apparatus'];?>" <?php if ($driveron['apparatus'] == $apparatus['apparatus']){echo "SELECTED";} ?> ><?php echo substr($apparatus['apparatus'], 5); ?></option>

                            <?php endforeach;?>

图片转代码服务由CSDN问答提供 功能建议

所以我遇到了这个问题,我看不出它是怎么回事。 基本上我有2个阵列,其中一个有一个设备列表,另一个只有一个用户可以操作的设备。 我想要一个可用的所有设备的下拉列表,但是所选择的默认值是他们可以操作的(他们一次只能操作一个)这是代码,我有一个if语句来检查 如果用户可以操作它并选择=“选中”但似乎没有工作(在Firefox中)......任何帮助都会很棒。


 foreach($ apparatuslist as $ apparatus):?&gt; 
&lt; option value =“&lt;?php echo $ apparatus ['apparatus'];  ?&gt;”中 &lt;?php if($ driveron ['apparatus'] == $ apparatus ['apparatus']){echo“SELECTED”;}?&gt;  &gt;&lt;?php echo substr($ apparatus ['apparatus'],5);  ?&gt;&lt; / option&gt; 
&lt;?php endforeach;?&gt; 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dsebywql016137
    dsebywql016137 2011-02-15 04:18

    You have it right in your question, but not in your code

        foreach ($apparatuslist as $apparatus):?>
        <option value="<?php echo $apparatus['apparatus'];?>" <?php if ($driveron['apparatus'] == $apparatus['apparatus']){echo "selected=\"selected\"";} ?> ><?php echo substr($apparatus['apparatus'], 5); ?></option>
    <?php endforeach;?>

    Should do the trick..

    点赞 评论
  • dongzhiman2162
    dongzhiman2162 2011-02-15 03:55

    correct syntax is: selected="selected" in OPTION tag

    点赞 评论
  • douti0687
    douti0687 2011-02-15 04:28

    The code is correct. It's optional whether you write select="selected" or jus "selected" that doesn't effect firefox.The code is correct but not working means the problem in browser i guess. Either it is cache problem as newer version of firefox has cache problem or there may be other kind of problem in firefox. Please check in other computer's firefox.

    点赞 评论