For loop did not work


I am new in using for loop to get the values from while loop:

here is my code:

$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
$res_bom = mysql_query($sql, $con);

while($row = mysql_fetch_assoc($res_bom)){

    $Items = $row['Items'];
echo "<tr>
        <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$Items' name='Items[]' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
        <td style='border:none;'>&nbsp;</td>
        <td style='border:none;'>&nbsp;</td>
        <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty[]' value='' size='7'></center></td>



Items – I input demanded qty
P28 -----1

when I debug my script by checking if what data was get bhy using for loop:

$Items = $_POST['Items'];
$DemandedQty = $_POST['DemandedQty'];
for($s = 0; $s <= count($Items); $s++){

echo $DemandedQty[$s];
echo '<br/>';
echo $Items[$s];


the ouput is:

I don’t know why only the last demanded qty was get.

I want output is :
P28- 1
P30- 2
P32 - 3

Thank you

Your id and name attribute values for DemandQty are back to front, the [] should be part of the name attribute and not the id attribute.

Thank you for your suggestion.

Now, I encountered error:

Column count doesn’t match value count at row 1

but when I count my row it was match:

for($i = 0; $i < count($Items1); $i++)

    if ( $DemandedQty[$i] != "" )
    $sql = "INSERT INTO stock_requisition
    (sr_date, sr_number, Items, SubItems, ItemCode, SubQty, UoM, Class, Description, BINLocation)
    ('$sr_date', '$sr_number', '$Items1[$i]', '$SubItems[$i]',  '$ItemCode[$i]', '$SubQty[$i]' '$UoM[$i]', '$Class[$i]', '$Description[$i]',
    $result = mysql_query($sql, $con) or die(mysql_error());


Thank you

I found my error: i forgot ‘,’ between $SubQty[$i] and $UoM[$i]

Thank you