我有一个选择框,其中包含从数据库生成的值。如何在存储在数据库中的值上选择它?
<select name="city" class="form-control">
<?php foreach($records->result_array() as $row) { ?>
<option value="<?=$row['id_city']?>">
<?=$row['city']?>, <?=$row['country']?>
</option>
<?php } ?>
</select>
答案 0 :(得分:0)
我想用不同的例子来解决
<?php
$con = mysql_connect("localhost","root","root");
$db = mysql_select_db("exampleTest",$con);
$get=mysql_query("SELECT id FROM example ORDER BY id ASC");
$option = '';
while($row = mysql_fetch_assoc($get))
{
$option .= '<option value = "'.$row['id'].'">'.$row['id'].'</option>';
}
?>
<html>
<body>
<form>
<select>
<?php echo $option; ?>
</select>
</form>
</body>
</html>