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.
This may help you. ? php $sql = "select * from mine where username = '$user' "; $res = mysql_query($sql); while($list = mysql_fetch_assoc($res)) { $category = $list['category']; $username = $list['username']; $options = $list['options']; ?> <input type="text" name="category" value="<?
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.
UPDATE:
As @Maninderpreet-Singh mentioned, you also need to change $row
to $rows
.
try to change
<option <?php echo($row->aC== "Deadpool") ? 'selected = "selected"': '';?> value="<?php echo $row->aC;?>">Deadpool</option>
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
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With