if(isset($_GET["id"])){
$sql=mysql_query("SELECT * FROM aMovie WHERE aName= '{$_GET['id']}'");
$row=mysql_fetch_object($sql);
}
<input type = "text" name = "name" value = "<?php echo $row->aC; ?>"/>
<select name = "name" >
<option value = "" <?php echo ($row->aC== "Deadpool") ? 'selected = "selected"': '';?>">Deadpool</option>
<option value = "" <?php echo ($row->aC == "BATMAN VS SUPERMAN") ? 'selected = "selected"': '';?>">BATMAN VS SUPERMAN</option>
</select>
Assume that aMovie is my table name, and in my table there are aName and and aC. However, I would want to display aName which matches aC ["Deadpool" or "Batman Vs Superman"] and display it in the drop down button. It only works for the input type but not the drop down button.
假设aMovie是我的表名,在我的表中有aName和aC。但是,我想显示一个匹配aC [“Deadpool”或“Batman Vs Superman”]的名称,并在下拉按钮中显示。它仅适用于输入类型,但不适用于下拉按钮。
4 个解决方案
#1
3
Your <select>
should be like:
你的
<select name = "name" >
<option value="Deadpool" <?=($rows->aC == "Deadpool" ? 'selected="selected"': '')?>>Deadpool</option>
<option value="BATMAN VS SUPERMAN" <?=($rows->aC == "BATMAN VS SUPERMAN" ? 'selected="selected"': '')?>>BATMAN VS SUPERMAN</option>
</select>
selected="selected"
will use outside the value
attribute.
selected =“selected”将在value属性之外使用。
UPDATE:
更新:
As @Maninderpreet-Singh mentioned, you also need to change $row
to $rows
.
正如@ Maninderpreet-Singh所提到的,你还需要将$ row更改为$ rows。
#2
1
try to change
试着改变
<option <?php echo($row->aC== "Deadpool") ? 'selected = "selected"': '';?> value="<?php echo $row->aC;?>">Deadpool</option>
#3
1
try with this and you are using different variable in input
试试这个,你在输入中使用不同的变量
<input type = "text" name = "name" value = "<?php echo $rows->aC; ?>"/>
$row
and $rows
are different
$ row和$ rows是不同的
<option value = "<?php echo $row->aC; ?>" <?php echo ($row->aC == "Deadpool") ? 'selected':'';?>">Deadpool</option>
<option value = "<?php echo $row->aC; ?>" <?php echo ($row->aC == "BATMAN VS SUPERMAN") ? 'selected': '';?>">BATMAN VS SUPERMAN</option>
#4
1
<input type = "text" name = "name1" value = "<?php echo $rows->aC; ?>"/>
<select name = "name2" >
<option value = " <?php echo($row->aC); ?>" <?php echo($row->aC=="Deadpool")?'selected': '';?>>Deadpool</option>
<option value = " <?php echo($row->aC);?>" <?php echo($row->aC == "BATMAN VS SUPERMAN")?'selected': '';?>>BATMAN VS SUPERMAN</option>
</select>
#1
3
Your <select>
should be like:
你的
<select name = "name" >
<option value="Deadpool" <?=($rows->aC == "Deadpool" ? 'selected="selected"': '')?>>Deadpool</option>
<option value="BATMAN VS SUPERMAN" <?=($rows->aC == "BATMAN VS SUPERMAN" ? 'selected="selected"': '')?>>BATMAN VS SUPERMAN</option>
</select>
selected="selected"
will use outside the value
attribute.
selected =“selected”将在value属性之外使用。
UPDATE:
更新:
As @Maninderpreet-Singh mentioned, you also need to change $row
to $rows
.
正如@ Maninderpreet-Singh所提到的,你还需要将$ row更改为$ rows。
#2
1
try to change
试着改变
<option <?php echo($row->aC== "Deadpool") ? 'selected = "selected"': '';?> value="<?php echo $row->aC;?>">Deadpool</option>
#3
1
try with this and you are using different variable in input
试试这个,你在输入中使用不同的变量
<input type = "text" name = "name" value = "<?php echo $rows->aC; ?>"/>
$row
and $rows
are different
$ row和$ rows是不同的
<option value = "<?php echo $row->aC; ?>" <?php echo ($row->aC == "Deadpool") ? 'selected':'';?>">Deadpool</option>
<option value = "<?php echo $row->aC; ?>" <?php echo ($row->aC == "BATMAN VS SUPERMAN") ? 'selected': '';?>">BATMAN VS SUPERMAN</option>
#4
1
<input type = "text" name = "name1" value = "<?php echo $rows->aC; ?>"/>
<select name = "name2" >
<option value = " <?php echo($row->aC); ?>" <?php echo($row->aC=="Deadpool")?'selected': '';?>>Deadpool</option>
<option value = " <?php echo($row->aC);?>" <?php echo($row->aC == "BATMAN VS SUPERMAN")?'selected': '';?>>BATMAN VS SUPERMAN</option>
</select>