0

So I'm passing along information from a previous form via POST array. When I attempt to pull information from the database, its not finding any records. Yet the data dump is showing that the array for "pre_fodder" has values. The array 'item' is coming up empty. Help =(

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++;

 }
4

1 回答 1

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);
}
于 2013-08-14T06:11:36.483 回答