SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Issue in while loop in a table

    I have query which I display data in while loop but my problem is the first repeated after the second row display.

    here is my code and also I attach the image display output.

    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 Images Attached Images

  2. #2
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try do the following near line 94.

    PHP Code:
    $num 0;
    while(
    $row mysql_fetch_assoc($result)){ 
        if (
    $num==0) {
            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>"
    ;       
        
    $num++;

    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications


Bookmarks

Posting Permissions

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