简体   繁体   English

如何在php的下拉菜单中选择选定的选项字段

[英]How to select the selected option field in dropdown in php

Consider the following command: echo '', $row['name'], ''; 考虑以下命令:echo'',$ row ['name'],'';

Now how do I add the following code into the code I'm doing does not work either. 现在,如何将以下代码添加到我正在执行的代码中也不起作用。

if ($row['name'] =='class2' )echo " selected "; 如果($ row ['name'] =='class2')echo“ selected”;

Try 尝试

if ($row['name'] =='class2' ){echo "selected=\"selected\"";}

edit: I hope I got your point right with that less informations... 编辑:我希望我能用较少的信息来正确表达您的观点...

just to put it right for you: 只是为了适合您:

<select>
<option 
<?
if ($row['name'] =='class2' )
{echo "selected=\"selected\"";}
?> value="<?=$row[name]?>">
<?=$row[name]?>
</option>
</select>

Do you mean something like this ? 你的意思是这样吗?

<option <?php echo $row['name']=='class2'?"selected='selected'":""; ?> 
    value="<?php echo $row['name'] ?>">
    <?php echo $row['name'] ?>
</option>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM