php pdo 如何从数据库中提取和设置默认值
php pdo how to pull down and set default values from the database
$select_stmt = $db->prepare('SELECT * FROM new_product WHERE `user_id` = :id');
$select_stmt->execute(array(':id'=>$_GET['id']));
$row = $select_stmt->fetch(PDO::FETCH_ASSOC);
<div class="form-group">
<label for="exampleFormControlSelect1">尺寸</label>
<select class="form-control" name ="Size" id="Size">
<option>30*60</option>
<option>15*90</option>
<option>15*17.3</option>
</select>
</div>
请问如何使用foreach将数据库中的值select带出为默认值。例如:我的数据库值为15 * 90,如何select option =15 * 90 我这里使用PDO
您需要创建一个循环来处理查询的所有结果,并将每一行的相关部分添加到 HTML
<?php
$select_stmt = $db->prepare('SELECT xx,desc FROM new_product WHERE `user_id` = :id');
$select_stmt->execute(array(':id'=>$_GET['id']));
?>
<div class="form-group">
<label for="exampleFormControlSelect1">尺寸</label>
<select class="form-control" name ="Size" id="Size">
<?php
while ( $row = $select_stmt->fetch(PDO::FETCH_ASSOC)) :
// these are just example column names as you dont tell us
// what the columns you want to use are called
echo "<option value='$row[xx]'>$row[desc]</option>";
endwhile;
?>
</select>
</div>
$select_stmt = $db->prepare('SELECT * FROM new_product WHERE `user_id` = :id');
$select_stmt->execute(array(':id'=>$_GET['id']));
$row = $select_stmt->fetch(PDO::FETCH_ASSOC);
<div class="form-group">
<label for="exampleFormControlSelect1">尺寸</label>
<select class="form-control" name ="Size" id="Size">
<option>30*60</option>
<option>15*90</option>
<option>15*17.3</option>
</select>
</div>
请问如何使用foreach将数据库中的值select带出为默认值。例如:我的数据库值为15 * 90,如何select option =15 * 90 我这里使用PDO
您需要创建一个循环来处理查询的所有结果,并将每一行的相关部分添加到 HTML
<?php
$select_stmt = $db->prepare('SELECT xx,desc FROM new_product WHERE `user_id` = :id');
$select_stmt->execute(array(':id'=>$_GET['id']));
?>
<div class="form-group">
<label for="exampleFormControlSelect1">尺寸</label>
<select class="form-control" name ="Size" id="Size">
<?php
while ( $row = $select_stmt->fetch(PDO::FETCH_ASSOC)) :
// these are just example column names as you dont tell us
// what the columns you want to use are called
echo "<option value='$row[xx]'>$row[desc]</option>";
endwhile;
?>
</select>
</div>