Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    136

    Unanswered: while loop inside while loop

    Hi..
    I have while loop inside while loop but I encountered problem in displaying data inside while loop or the second while loop.

    here is my code:

    Code:
    <?php
      error_reporting(0);
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    ?>
    <script type="text/javascript">
    function showDetails(pcode) {
     
     var clickElement = pcode.value;
     var click_id = pcode.id; 
                   
    // var value_ =  document.getElementById(click_id).checked
     //    =  document.getElementById(clickElement).checked;   
     //var Table = (document.getElementsByName('list')[0].value);     
     
     var Table = document.getElementById('kanban_list'); 
    
     var rows = Table.rows;   
     
     var strSelect = document.getElementById(click_id).value;
     //alert(strSelect)
     
     for (var i = 0; i < rows.length; i++) {      
          var row = rows[i];      
        //row.style.display = (row.id.substr(0,3) == strSelect) ?      'none'         :          '';   
        //row.style.display = (row.id.substr(0,3) == strSelect) ? 
       // row.style.display = 'none';
       // row.style.display = '';
        
        if (row.id.substr(0,3) == strSelect) {
            row.style.display = ((document.getElementById(click_id).checked) == false) ?  'none' : ''
        }
        //(document.getElementById(click_id).checked == false) ?  'none'               : '' : '';   
     
     }  
       
    }
    
    </script>
    <?php
    $sql = "SELECT kc.PCODE, kc.count_wip_chemical_weighing, kc.count_wip_compounding, kc.count_wip_extrusion, 
    kc.count_wip_forming, kc.count_wip_deflashing, kc.kanban, kc.virtual, p.max_lot, p.min_lot FROM kanban_checker kc 
    JOIN plan p ON kc.PCODE = p.PCODE ORDER BY p.PCODE";    
    $result = mysql_query($sql, $con);       
    ?><label>Display Details:</label><input  onclick='showDetails(this);' id='chkDetail'   type='checkbox' checked='checked' value='wip'/>
    <?php
    echo "<table id='kanban_list'>";
    echo "<tr>
            <th> PCODE </th>
            <th> LOT CODE </th>
            <th> CHEMICAL WEIGHING </th>
            <th> COMPOUNDING </th>
            <th> EXTRUSION </th>
            <th> FORMING </th>
            <th> DEFLASHING </th>
            <th> KANBAN </th>
            <th> VIRTUAL </th>
            <th> MAX LOT </th>
            <th> MIN LOT </th>
         </tr>";
    while($row = mysql_fetch_assoc($result)){ 
        echo "<tr>
            <td>$row[PCODE]</td>
            <td>&nbsp;</td>
           <!-- <td>$row[LOT_CODE]</td>   -->
            <td>$row[count_wip_chemical_weighing]</td>
            <td>$row[count_wip_compounding]</td>
            <td>$row[count_wip_extrusion]</td>
            <td>$row[count_wip_forming]</td>
            <td>$row[count_wip_deflashing]</td>
            <td>$row[kanban]</td>
            <td>$row[virtual]</td>
            <td>$row[max_lot]</td>
            <td>$row[min_lot]</td>
            </tr>";     
    $sql = "SELECT kd.LOT_CODE, kd.wip_chemicalweighing, kd.wip_compounding, kd.wip_extrusion, kd.wip_forming, kd.wip_deflashing 
    FROM kanban_data kd JOIN plan p ON kd.PCODE = p.PCODE ORDER BY p.PCODE "; 
    $result_kanban_data = mysql_query($sql, $con);   
    
    while($row_data = mysql_fetch_assoc($result_kanban_data)){    
        echo "<tr id='wip'>
        <td></td>
        <td>&nbsp;$row_data[LOT_CODE]</td>
        <td>&nbsp;$row_data[wip_chemicalweighing]</td>
        <td>&nbsp;$row_data[wip_compounding]</td>
        <td>&nbsp;$row_data[wip_extrusion]</td>
        <td>&nbsp;$row_data[wip_forming]</td>
        <td>&nbsp;$row_data[wip_deflashing]</td>
        </tr>"; 
    }       
    }
    echo "</table>";
         
    ?>
    I attach the image of result from this code

    But the output that I want is all LOT_CODE with P35 PCODE will only display below P35
    and all LOTCODE with P35M PCODE will only display below P35M.

    Thank you

    I hope somebody can help me..
    Attached Thumbnails Attached Thumbnails kanban.JPG  

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    why do you think your current code isn't working?
    think in terms of the program logic, not in terms of P35 / P35M

    each time you retrieve data from a remoter database there is delay, unless you have to keep the number of SQL statements to a minimum. gratned the major 'cost' is the establishing of the connection to the database

    why do think you need a 'while loop inside while loop';?
    what is wrong with the approach suggested in your previous post
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2010
    Posts
    136
    I revise my code:

    Code:
    <?php
      error_reporting(0);
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    ?>
    <style type="text/css">
    table {
        margin: 9px;
    }
    
    th {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        background: #694;
        color: #FFF;
        padding: 2px 6px;
        border-collapse: separate;
        border: 1px solid #000; 
    }    
    
    td {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        border: 1px solid #DDD;
        text-align: right;
    }  
    </style>
    <script type="text/javascript">
    function showDetails(pcode) {
     
     var clickElement = pcode.value;
     var click_id = pcode.id; 
                   
    // var value_ =  document.getElementById(click_id).checked
     //    =  document.getElementById(clickElement).checked;   
     //var Table = (document.getElementsByName('list')[0].value);     
     
     var Table = document.getElementById('kanban_list'); 
    
     var rows = Table.rows;   
     
     var strSelect = document.getElementById(click_id).value;
     //alert(strSelect)
     
     for (var i = 0; i < rows.length; i++) {      
          var row = rows[i];      
        //row.style.display = (row.id.substr(0,3) == strSelect) ?      'none'         :          '';   
        //row.style.display = (row.id.substr(0,3) == strSelect) ? 
       // row.style.display = 'none';
       // row.style.display = '';
        
        if (row.id.substr(0,3) == strSelect) {
            row.style.display = ((document.getElementById(click_id).checked) == false) ?  'none' : ''
        }
        //(document.getElementById(click_id).checked == false) ?  'none'               : '' : '';   
     
     }  
       
    }
    
    </script>
    <?php
    
    $sql = "SELECT kc.PCODE, kd.LOT_CODE, kd.wip_chemicalweighing, kd.wip_compounding, kd.wip_extrusion, kd.wip_forming, 
    kd.wip_deflashing, kc.count_wip_chemical_weighing, kc.count_wip_compounding, kc.count_wip_extrusion, kc.count_wip_forming, 
    kc.count_wip_deflashing, kc.kanban, kc.virtual, p.max_lot, p.min_lot 
    FROM kanban_data kd JOIN kanban_checker kc ON kd.PCODE = kc.PCODE 
    JOIN plan p ON kc.PCODE = p.PCODE  ORDER BY kc.PCODE";    
    $result = mysql_query($sql, $con);       
    
    ?><label>Display Details:</label><input  onclick='showDetails(this);' id='chkDetail'   type='checkbox' checked='checked' value='wip'/>
    <?php
    echo "<table id='kanban_list'>";
    echo "<tr>
            <th> PCODE </th>
            <th> LOT CODE </th>
            <th> CHEMICAL WEIGHING </th>
            <th> COMPOUNDING </th>
            <th> EXTRUSION </th>
            <th> FORMING </th>
            <th> DEFLASHING </th>
            <th> KANBAN </th>
            <th> VIRTUAL </th>
            <th> MAX LOT </th>
            <th> MIN LOT </th>
         </tr>";    
    while($row = mysql_fetch_assoc($result)){ 
        echo "<tr>
            <td>$row[PCODE]</td>
            <td>&nbsp;</td>
           <!-- <td>$row[LOT_CODE]</td>   -->
            <td>$row[count_wip_chemical_weighing]</td>
            <td>$row[count_wip_compounding]</td>
            <td>$row[count_wip_extrusion]</td>
            <td>$row[count_wip_forming]</td>
            <td>$row[count_wip_deflashing]</td>
            <td>$row[kanban]</td>
            <td>$row[virtual]</td>
            <td>$row[max_lot]</td>
            <td>$row[min_lot]</td>
            </tr>";   
                    
        echo "<tr id='wip'>
        <td></td>
        <td>&nbsp;$row[LOT_CODE]</td>
        <td>&nbsp;$row[wip_chemicalweighing]</td>
        <td>&nbsp;$row[wip_compounding]</td>
        <td>&nbsp;$row[wip_extrusion]</td>
        <td>&nbsp;$row[wip_forming]</td>
        <td>&nbsp;$row[wip_deflashing]</td>
        </tr>";       
    }
    
    echo "</table>";
         
    ?>
    I attach the output:

    I want to display the first row once..I think the problem is in my logic condition.but I don't know how can I change my condition. to display the first row once and after the row display the second row which has lot codes.

    Thank you
    Attached Thumbnails Attached Thumbnails kanban1.JPG  
    Last edited by newphpcoder; 02-29-12 at 20:50.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Add some code like this.
    Code:
    first_switch="Y"
    while (row= .......................)
    {
      if first_switch == "Y"
         {
         display first row
         first_switch= "N"
         }
    else
        {
         display subsequent row
         }
    }

Posting Permissions

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