①district_tw, ②status_affect
$tb_af='status_affect';
$sql="SELECT * FROM $tb_af ORDER BY id";
PDOstatement
物件$stmt1=$prime->prepare($sql);
$stmt1->execute();
$row=$stmt1->fetch();
#$row=$stmt1->fetch(PDO::FETCH_OBJ);
#$row=$stmt1->fetch(PDO::FETCH_LAZY);
#$row=$stmt1->fetch(PDO::FETCH_BOTH);
#$row=$stmt1->fetch(PDO::FETCH_ASSOC);
#$row=$stmt1->fetch(PDO::FETCH_NUM);
$stmt1->execute();
echo '<ol>';
while($row=$stmt1->fetch(PDO::FETCH_OBJ)){
echo "<li>$row->id, $row->affect</li>";
}
echo '</ol>';
<select>
下拉選項$stmt1->execute();
echo '<label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>';
while($row=$stmt1->fetch(PDO::FETCH_OBJ)){
printf('<option value="%s">%s</option>',$row->id, $row->affect);
#echo "<option value=\"$row->id\">$row->affect</option>";
}
echo '</select>';
selected
)$selected=2;
$stmt1->execute();
echo '<label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>';
while($row=$stmt1->fetch(PDO::FETCH_OBJ)){
printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$selected?' selected':'', $row->affect);
}
echo '</select>';
if($stmt1->execute()){
echo '<label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>';
while($row=$stmt1->fetch(PDO::FETCH_OBJ)){
printf('<option value="%s">%s</option>',$row->id, $row->affect);
}
echo '</select>';
}
$tb_af='status_affect';
$sql="select * from $tb_af ORDER BY id";
try{
$stmt1=$prime->prepare($sql);
if($stmt1->execute()){
echo '<label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>';
while($row=$stmt1->fetch(PDO::FETCH_OBJ)){
printf('<option value="%s">%s</option>',$row->id, $row->affect);
}
echo '</select>';
}
}
catch(PDOException $e){
echo $e->getMessage();
exit;
}
更新日期: