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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Got problem in table layout

    Hi,

    I got problem in my table layout.

    my table data came from database using php while loop and foreach.

    Here is my scenario.

    I need to display the reject type per date.
    like this:

    Compound-- space---2013-07-24 2013-07-25
    Compound Mixing----SC-SP-SH----PG-PT

    2013-07-24 has 3 reject types SC SP SH
    2013-07-25 has 2 reject types PG PT

    i want to display the reject type on the date where its belong.
    but in this code:

    Code:
     
    <table><tr><thead><th>Compound</th><th>2013-07-24</th><th>2013-07-25</th></thead></tr><tr><td>Compound Mixing</td><td>SC</td><td>SP</td><td>SH</td><td>PG</td><td>PT</td></table>
    the output is like this:
    as you can see the SC and SP was size like the size of the date. but it supposively 3 reject type within 2013-07-24 and 2 for 2013-07-25

    Compound-- space---2013-07-24 2013-07-25
    Compound Mixing---SC----------SP-----------SH-PG-PT


    and here is the php code:

    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";

    $id "30";
    if(
    $id == '30')
    {    

       
    //----code for date only----//
       
    $sql "SELECT DISTINCT r.reject_date, r.process_id
        FROM op_reject AS r 
        JOIN process_list AS p ON (p.process_id = r.process_id)
        WHERE WEEK(reject_date) + 1 = '$id'
        GROUP BY r.reject_date ORDER BY r.reject_date  ASC"

        
        
        
    $res mysql_query($sql);
        
        echo 
    "<table>";
        echo 
    "<tr>";
        echo 
    "<thead>";
        echo 
    "<th>Compound</th>";

        while(
    $row mysql_fetch_assoc($res))
        {
            
    $report_date[]  = $row['reject_date'];
            
    $process_[]   = $row['process_id'];
        }
        
            foreach(
    $report_date AS $report_date)
            {
                echo 
    "<th>$report_date</th>"
            }
            echo 
    "</thead>";
        echo 
    "</tr>";

            
    $sql_comp "SELECT DISTINCT p.process_name , r.process_id, r.reject_date
            FROM op_reject AS r 
            JOIN process_list AS p ON (p.process_id = r.process_id)
                    WHERE WEEK(reject_date) + 1 = '$id' GROUP BY process_name ORDER BY p.process_id ASC"
    ;     
            
    $res_comp mysql_query($sql_comp);
            
            
                 echo 
    "<tr>";
                 while(
    $row_comp mysql_fetch_assoc($res_comp))
                 {
                                    
                    
    $process      $row_comp['process_name'];
                    
    $process_id   $row_comp['process_id'];
                    
    $reject_date  $row_comp['reject_date'];
                  
                    echo 
    "<td>$process</td>";

                
    $sql_date "SELECT DISTINCT r.reject_date
    FROM op_reject AS r 
    JOIN process_list AS p ON (p.process_id = r.process_id)
    WHERE WEEK(reject_date) = '$id'
    GROUP BY r.reject_date ORDER BY r.reject_date  ASC"

    $res_date mysql_query($sql);

    while(
    $row_date mysql_fetch_assoc($res_date))
    {
        
    $report_date_  $row_date['reject_date'];                                         

        
        
    $sql_rej "SELECT DISTINCT reject_type FROM op_reject WHERE reject_date = '$report_date_' and process_id = '$process_id'";
            
    $res_rej mysql_query($sql_rej);
            
    $cnt_rej mysql_num_rows($res_rej);
            
            
            if(
    $cnt_rej 0)
            {
                while(
    $row_rej=mysql_fetch_assoc($res_rej))
                {
                    
    $reject_type $row_rej['reject_type'];
                    
                    echo 
    "<td>$reject_type</td>";
                }
            }   
    }

         }   
      echo 
    "</table>"
     }
    ?>

    I hope somebody can help me through this.


    Thank you so much.

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    264
    Thanks
    49
    Thanked 1 Time in 1 Post
    What does each - specify? A blank table cell?

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SRD75 View Post
    What does each - specify? A blank table cell?
    What do you mean blank table cell??

    Thank you

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Please see attached file for sample layout.


    Thank you.
    Attached Thumbnails Attached Thumbnails Got problem in table layout-table.jpg  

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    264
    Thanks
    49
    Thanked 1 Time in 1 Post
    I mean
    Code:
    <td></td>

  • #6
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    before I tried to use colspan but the problem is the reject type are not consistent or it has a default value it can be 1 or many.

    Thank you

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    264
    Thanks
    49
    Thanked 1 Time in 1 Post
    Why can't you use TH colspan="3" for both dates in the top row?

  • #8
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SRD75 View Post
    Why can't you use TH colspan="3" for both dates in the top row?
    I can't because the reject type was not consisted as 3. it can be 4 or 7 or 9
    Thank you

  • #9
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Well what if you pull the first query's data into an array, and save it for later, then select the COUNT of the rejects in the second query.

    Then you will have all the data in two arrays and you can build the table, using the COUNT of the rejects as the colspan in the first row.

    This only would work of course if you have only one row of data, as your diagram showed.

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #10
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    Can't test this because I don't have your database.
    I also assume 3 cols are normal, but you can alter this.
    I use javascrict to change the colspan attribute in your <thead> cells.
    In php file change this and I added too much to show you location:
    PHP Code:
        while($row mysql_fetch_assoc($res))
        {
            
    $report_date[]  = $row['reject_date'];
            
    $process_[]   = $row['process_id'];
        }
        
            foreach(
    $report_date AS $report_date)
            {
                echo 
    "<th>$report_date</th>"
            }
            echo 
    "</thead>";
        echo 
    "</tr>"
    To:
    PHP Code:
    $i 1;
            foreach(
    $report_date AS $report_date)
            {
                echo 
    "<th id=col".$i." colspan=\"3\">$report_date</th>";
                
    $i++;
            }
            echo 
    "</thead>";
        echo 
    "</tr>"
    It adds a colspan of 3 to every th and an ID and a variable that knows how many rejected cells there will be.

    Add this someplace to put it in the HTML code:
    PHP Code:
    echo '
    <script type="text/javascript">
        document.getElementById("col2").colSpan='
    .$i.';
    </script>'

    Evolution - The non-random survival of random variants.

  • #11
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Hi,

    Attached my database.


    Thank you
    Attached Files Attached Files

  • #12
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Thank you...it works now, but i try to add some of my codes.

    Thank you

  • #13
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Hi,

    here is my new code:

    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";

    $id "30";
    if(
    $id == '30')
    {    

       
    //----code for date only----//
       
    $sql "SELECT DISTINCT r.reject_date, r.process_id
        FROM op_reject AS r 
        JOIN process_list AS p ON (p.process_id = r.process_id)
        WHERE WEEK(reject_date) + 1 = '$id'
        GROUP BY r.reject_date ORDER BY r.reject_date  ASC"

        
        
        
    $res mysql_query($sql);
     
        echo 
    "<table>";
        echo 
    "<tr>";
        echo 
    "<thead>";
        echo 
    "<th>Compound</th>";

        while(
    $row mysql_fetch_assoc($res))
        {
            
    $report_date[]  = $row['reject_date'];
            
    $process_[]   = $row['process_id'];
        }
        
            
    $i 1;
            foreach(
    $report_date AS $report_date)
            {
                echo 
    "<th id=col".$i." colspan=\"3\">$report_date</th>";
                
    $i++;
            }
            echo 
    "</thead>";
        echo 
    "</tr>";  
        echo 
    '
    <script type="text/javascript">
        document.getElementById("col2").colSpan='
    .$i.';
    </script>'

            
    $sql_comp "SELECT DISTINCT p.process_name , r.process_id, r.reject_date
            FROM op_reject AS r 
            JOIN process_list AS p ON (p.process_id = r.process_id)
                    WHERE WEEK(reject_date) + 1 = '$id' GROUP BY process_name ORDER BY p.process_id ASC"
    ;     
            
    $res_comp mysql_query($sql_comp);
            
            
                 echo 
    "<tr>";
                 while(
    $row_comp mysql_fetch_assoc($res_comp))
                 {
                                    
                    
    $process      $row_comp['process_name'];
                    
    $process_id   $row_comp['process_id'];
                    
    $reject_date  $row_comp['reject_date'];
                  
                    echo 
    "<td>$process</td>";
        
                
    $sql_date "SELECT DISTINCT r.reject_date
                                                        FROM op_reject AS r 
                                                        JOIN process_list AS p ON (p.process_id = r.process_id)
                                                        WHERE WEEK(reject_date) = '$id'
                                                        GROUP BY r.reject_date ORDER BY r.reject_date  ASC"

                                                        
    $res_date mysql_query($sql);
                                    
                                                        while(
    $row_date mysql_fetch_assoc($res_date))
                                                        {
                                                            
    $report_date_  $row_date['reject_date'];                                         

                                                            
                                                            
    $sql_rej "SELECT DISTINCT reject_type FROM op_reject WHERE reject_date = '$report_date_' and                                                                  process_id = '$process_id' ORDER BY reject_type";
                                                            
    $res_rej mysql_query($sql_rej);
                                                            
    $cnt_rej mysql_num_rows($res_rej);
                                                            
                                                            
                                                            if(
    $cnt_rej 0)
                                                            {
                                                            while(
    $row_rej=mysql_fetch_assoc($res_rej))
                                                            {
                                                                
    $reject_type $row_rej['reject_type'];
                                                                
                                                                echo 
    "<td>$reject_type</td>";
                                                            }
                                                            }   
                                                        }
        
                                    
    $comp "
                                    (SElECT DISTINCt r.compound_type FROM op_reject AS r WHERE r.process_id = '$process_id'  AND WEEK(r.reject_date) + 1 = '$id')
                                    ORDER BY compound_type ASC"
    ;

                                        
    $c mysql_query($comp);
                                        
                                        
    $cnt mysql_num_rows($c);
                                                
                                                echo 
    "<tr>";
                                                while(
    $co mysql_fetch_assoc($c))
                                                {
                                                        
    $compound_type   $co['compound_type'];
                                                        
    $process_i       $co['process_id'];
                                                        
    $shift_date      $co['shift_date'];  
                                                     
                                                        echo 
    "<td>$compound_type</td>"
                                                     
                                                        
    $sql_date "SELECT DISTINCT r.reject_date
                                                        FROM op_reject AS r 
                                                        JOIN process_list AS p ON (p.process_id = r.process_id)
                                                        WHERE WEEK(reject_date) = '$id'
                                                        GROUP BY r.reject_date ORDER BY r.reject_date  ASC"

                                                        
    $res_date mysql_query($sql);
                                    
                                                        while(
    $row_date mysql_fetch_assoc($res_date))
                                                        {
                                                            
    $report_date_  $row_date['reject_date'];                                         
                                    
                                                        
    //-----
                                                 
                                                 
                                                        //-----
                                                        
    $sql_reject "SELECT compound_type, SUM(reject) AS reject, reject_type FROM op_reject 
    WHERE compound_type = '$compound_type' and process_id = '$process_id' AND reject_date = '$report_date_' GROUP BY  compound_type, process_id, reject_TYPE"
    ;
                                                        
    $res_reject mysql_query($sql_reject);
                                                        
                                                        
    $cnt_rej mysql_num_rows($res_reject);
                                                       
                                                       if(
    $cnt_rej 0
                                                       {
                                                        
                                                        while(
    $row_reject mysql_fetch_assoc($res_reject))
                                                        {
                                                            
    $reject $row_reject['reject'];   
                                                          
                                                            echo 
    "<td>$reject</td>";         
                                                            
                                                       }
                                                       }
                                                       else
                                                       {
                                                           echo 
    "<td></td>";
                                                       }  
                                                        }

                                                       echo 
    "</tr>";
                                              

                } 

         }   
      echo 
    "</table>"
     }
    ?>
    and now i got a problem in displaying the rejects amount per reject type.
    for better understanding I attached my updated database, the screenshot display for this code and also the correct output i need to display.

    Thank you so much
    Attached Thumbnails Attached Thumbnails Got problem in table layout-new-output.jpg   Got problem in table layout-need-table-output.jpg  
    Attached Files Attached Files

  • #14
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You're going to need to make sure you put in empty tds to fill out each row, even if there isn't three rejects for that specific row. So, you'll need to refer back to the report_date array to find out what the colspan was for the current report.

    So, I think this is the right spot:
    PHP Code:
    [B]$counter 0;[/B]
     if(
    $cnt_rej 0)
      {
      while(
    $row_rej=mysql_fetch_assoc($res_rej))
      {
       
    $reject_type $row_rej['reject_type'];
       echo 
    "<td>$reject_type</td>";
       
    $counter++;
      }
      if(
    $counter < [THE COLSPAN FOR THIS REPORT DATE])
     { 
       
    $remaining = [THE COLSPAN FOR THIS REPORT DATE] - $counter;
       for(
    $i 0$i $remaining$i++)
       {
         echo 
    "<td>&nbsp;</td>\n"
       
    }
     }                                                     
     } 
    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #15
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by whizard View Post
    You're going to need to make sure you put in empty tds to fill out each row, even if there isn't three rejects for that specific row. So, you'll need to refer back to the report_date array to find out what the colspan was for the current report.

    So, I think this is the right spot:
    PHP Code:
    [B]$counter 0;[/B]
     if(
    $cnt_rej 0)
      {
      while(
    $row_rej=mysql_fetch_assoc($res_rej))
      {
       
    $reject_type $row_rej['reject_type'];
       echo 
    "<td>$reject_type</td>";
       
    $counter++;
      }
      if(
    $counter < [THE COLSPAN FOR THIS REPORT DATE])
     { 
       
    $remaining = [THE COLSPAN FOR THIS REPORT DATE] - $counter;
       for(
    $i 0$i $remaining$i++)
       {
         echo 
    "<td>&nbsp;</td>\n"
       
    }
     }                                                     
     } 
    HTH
    Dan
    Is it [THE COLSPAN FOR THIS REPORT DATE] = $report_date_?


    Thank you


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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