Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts

    for loop did not work

    Hi..

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

    here is my code:

    PHP 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>
            
            </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:

    PHP Code:
    $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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post the html to your form.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •