Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

while loop inside while loop

loop

  • Please log in to reply
2 replies to this topic

#1 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 29 February 2012 - 01:41 AM

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:

<?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> </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> $row_data[LOT_CODE]</td>
    <td> $row_data[wip_chemicalweighing]</td>
    <td> $row_data[wip_compounding]</td>
    <td> $row_data[wip_extrusion]</td>
    <td> $row_data[wip_forming]</td>
    <td> $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

  • kanban.JPG

  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 29 February 2012 - 04:35 AM

your inner query needs to filter on the data from the outer query, so for each inner loop, you need to add a WHERE field = 'data from outer result' if you understand what I mean?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 29 February 2012 - 04:51 PM

I don't understand what you mean.can you site an example.but I revised my code:

I revise my 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> </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> $row[LOT_CODE]</td>
    <td> $row[wip_chemicalweighing]</td>
    <td> $row[wip_compounding]</td>
    <td> $row[wip_extrusion]</td>
    <td> $row[wip_forming]</td>
    <td> $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

  • kanban1.JPG

Edited by newphpcoder, 29 February 2012 - 05:49 PM.

  • 0





Also tagged with one or more of these keywords: loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download