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

 }

1 Answer 1

1

you don't have to loop, you can do it in single query using a IN clause

$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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.