所以我通过POST数组传递来自前一个表单的信息。当我尝试从数据库中提取信息时,它没有找到任何记录。然而,数据转储显示" pre_fodder"有价值。阵列'项目'即将到来。帮助=(
HTML
<div>
stuff here <br />
<input type="checkbox" name="pre_fodder[]" value="<? item[item_id} ?>" />
</div>
<div>
stuff here <br />
<input type="checkbox" name="pre_fodder[]" value="<? item[item_id} ?>" />
</div>
<div>
stuff here <br />
<input type="checkbox" name="pre_fodder[]" value="<? item[item_id} ?>" />
</div>
PHP
$i = 0;
$a = count($_POST['pre_fodder']);
while ( $i < $a ) {
print_r ($_POST[pre_fodder][$i]);
$_POST[pre_fodder][$i] += 0;
print_r ($_POST[pre_fodder][$i]);
$data = "SELECT * FROM items WHERE inventory_id='$_POST[pre_fodder][$i]'";
$result = mysqli_query($data);
$item = mysqli_fetch_assoc($result);
print_r($item);
$i++;
}
答案 0 :(得分:1)
您不必循环,您可以使用IN
子句
$sql = "SELECT * FROM items WHERE inventory_id IN ('" . implode("','", $_POST['pre_fodder']) ."')";
$rs = mysql_query($sql);
while ($r = mysql_fetch_assoc($rs)) {
print_r($r);
}