Results 1 to 2 of 2

Thread: for loop did not work

  1. #1
    Join Date
    Sep 2010
    Posts
    188

    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. #2
    Join Date
    Mar 2012
    Posts
    93
    may be error in MySQL query and may be you not proper used count()... you are used foreach instead of forloop...

Similar Threads

  1. while loop inside while loop
    By newphpbees in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 19 Apr 2012, 03:59 AM
  2. for loop issue!
    By efc_90 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 10 Jan 2011, 05:25 PM
  3. two records from the same table in for loop
    By catalepticstate in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 11 Oct 2010, 04:26 AM

Posting Permissions

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