/    Sign up×
Community /Pin to ProfileBookmark

for loop did not work

Hi..

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

here is my code:

[code=php]
$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>

</tr>”;
}
[/code]

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:

[code=php]
$Items = $_POST[‘Items’];
$DemandedQty = $_POST[‘DemandedQty’];
for($s = 0; $s <= count($Items); $s++){

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

}
[/code]

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 16.2012 — <i>
</i>$Items[b][color=red][][/color][/b] = $row['Items'];
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...