我有一个包含3个字段looking_id
,user_id
,looking
的表格。 looking_id
是独一无二的。
$sql="SELECT looking_id,user_id,looking FROM `provider_service_need` WHERE `user_id`='$user_id'";
$stmt=$dbg->query($sql);
<input type="checkbox" name="What_services[]" id="What_services" value="person_care" <?php if($stmt=='person_care')echo checked;?> >
<input type="checkbox" name="What_services[]" id="What_services" value="child_care" <?php if($stmt=='child_care')echo checked;?> >
<input type="checkbox" name="What_services[]" id="What_services" value="pet_care" <?php if($stmt=='pet_care')echo checked;?> >
但它不起作用。
答案 0 :(得分:1)
试试这个
$sql="SELECT looking_id,user_id,looking FROM `provider_service_need` WHERE `user_id`='$user_id'";
$stmt=mysql_query($sql);
while($result = mysql_fetch_array($stmt))
{
?>
<input type="checkbox" name="What_services[]" id="What_services_<?php echo $result['looking'];?>" value="person_care" <?php if($result['looking']=='person_care')echo "checked";?> >
<?php
} ?>
答案 1 :(得分:0)
对于pdo试试这个
$sql="SELECT looking_id,user_id,looking FROM `provider_service_need` WHERE `user_id`='$user_id'";
foreach ($stmt->query($sql) as $row)
{
?>
<input type="checkbox" name="What_services[]" id="What_services_<?php echo $row['looking'];?>" value="person_care" <?php if($row['looking']=='person_care')echo "checked";?> >
<?php
} ?>