newphpbees
16 Apr 2012, 04:41 AM
Hi..
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;'> <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;'> </td>
<td style='border:none;'> </td>
<td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty[]' value='' size='7'></center></td>
</tr>";
}
sample:
Items -- I input demanded qty
P28 -----1
P30------2
P32------3
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:
3
P28
P30
P32
I don't know why only the last demanded qty was get.
I want output is :
P28- 1
P30- 2
P32 - 3
Thank you
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;'> <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;'> </td>
<td style='border:none;'> </td>
<td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty[]' value='' size='7'></center></td>
</tr>";
}
sample:
Items -- I input demanded qty
P28 -----1
P30------2
P32------3
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:
3
P28
P30
P32
I don't know why only the last demanded qty was get.
I want output is :
P28- 1
P30- 2
P32 - 3
Thank you