PHP – Input returning only one item from Array

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

Good day!

<?php

$db = “SELECT * FROM table”;
$stmt = $conn->prepare($db);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($results as $row)
{
?>
<input type=”text” name=”test[]” value=”<?php echo $row[‘id’] ?>”>

<?php
}

print_r($_POST[‘test’]);

?>

I have this input field inside a foreach loop. I am doing a SELECT query from my database and outputting the data to value=””. When I print_r($_POST[‘test’]);, it only returns 1 item from the array. I am trying to achieve multiple items returned from the array and that will go to my count($_POST[‘test’]) and the total of items I have, I will run a DELETE query.

Am I missing something in my code, or is the way I’m approaching this shouldn’t be the way? I hope I did my best to display my code & what I have done to get the issue/try to get the expected results and hope to improve from this and better understand the use of loops and arrays! Thank you all.

‫أضف إجابة

تصفح
تصفح

مجهول يجيب