我试图检查数组中的任何值是否与数据库中的结果匹配,如果匹配,那么我想回显一个选中的复选框和填写的文本输入。
这是我到目前为止所拥有的。
$faucets_checked = unserialize($rotator_websites);
$check_these = array();
for ($x = 0; $x <= (intval(count($faucets_checked))-1); $x++){
$faucet_website_checked = explode("=",$faucets_checked[$x]);
$check_these[] = $faucet_website_checked[0] . "=";
$ref_these[] = $faucet_website_checked[1];
}
//SELECTED SOME DATA FROM DATABASE
while($stmt->fetch()){
$count = 0;
while($count <= (intval(count($check_these))-1)){
$check_this = $check_these[$count];
if($check_this == $faucet_website){
$checked = "checked";
$ref_filled = "value='".$ref_these[$count]."'";
echo "<input type='checkbox' name='check[]' value='".$faucet_id."' ".$checked." /><input type='text' name='text".$faucet_id."' ".$ref_filled." />";
}else{
$checked = "";
$ref_filled = "";
echo "<input type='checkbox' name='check[]' value='".$faucet_id."' ".$checked." /><input type='text' name='text".$faucet_id."' ".$ref_filled." />";
}
$checked = "";
$ref_filled = "";
$count++;
}
}
我发现这确实会返回一个复选框和输入文本字段,但也会返回另一个不检查且未填写的文本字段。