0 Replies Latest reply on Apr 27, 2011 1:45 PM by only1wizard

    how to create a dynamic table

    only1wizard Level 1
      i'm trying to achive this results layout:  

      example:
                           catagory
                                 comment
                                 comment
                                 comment
                           catagory
                           catagory
                           catagory
                                 comment

      what is being pulled now is if their is 2 comments two 1 catagory then 2 catagorys are being returned with the same id. what i want is to return one cataogry with many comments.

      thanks in advance for your help.




      <?php
      require_once('Connections/Del_Comments.php'); ?>

          <?php
          $all_ids
      = array();
         
      $str_ids = "";
          
         
      // first parent query
         
      $maxRows_sourceType = 10;
         
      $pageNum_sourceType = 0;
          if (isset(
      $_GET['pageNum_sourceType'])) {
           
      $pageNum_sourceType = $_GET['pageNum_sourceType'];
          }
         
      $startRow_sourceType = $pageNum_sourceType * $maxRows_sourceType;
          
         
      mysql_select_db($database_Del_Comments, $Del_Comments);
         
      $query_sourceType = "SELECT a.Id, a.Type,
      a.Dates,
      a.UIdFk,
      b.Id as Did,
      b.comment,
      b.dates as Day,
      b.sfk as Sfk ,
      c.sfk as sfk1,
      d.Memo as memo
      FROM
      asstatusupdate as a  
      left join asstatusdata as b
      on a.id = b.sfk
      left join asmanystatusupdate as c
      on b.sfk = c.sfk
      left join ascomments as d
      on d.id = c.cfk
      where a.uidfk='1'
      order by Dates asc"
      ;
         
      $query_limit_sourceType = sprintf("%s LIMIT %d, %d", $query_sourceType, $startRow_sourceType, $maxRows_sourceType);
         
      $sourceType = mysql_query($query_limit_sourceType, $Del_Comments) or die(mysql_error());
         
      $row_sourceType = mysql_fetch_assoc($sourceType);
          
          if (isset(
      $_GET['totalRows_sourceType'])) {
           
      $totalRows_sourceType = $_GET['totalRows_sourceType'];
          } else {
           
      $all_sourceType = mysql_query($query_sourceType);
           
      $totalRows_sourceType = mysql_num_rows($all_sourceType);
          }
         
      $totalPages_sourceType = ceil($totalRows_sourceType/$maxRows_sourceType)-1;
          
         
      // add the array
         
      while ($row_source = mysql_fetch_assoc($sourceType)) {
          
             
      $all_ids[] = $row_source['Sfk'];
          
             
      $str_ids .= $row_source['Sfk'].',';
          
           }
          
                 
      // remove the array
              
      $str_ids = (substr($str_ids,-1) == ',') ? substr($str_ids, 0, -1) : $str_ids;
         
           echo $str_ids;
         
      //echo $all_ids;
           
           //second child query
             
      $maxRows_sourceComments = 10;
         
      $pageNum_sourceComments = 0;
          if (isset(
      $_GET['pageNum_sourceComments'])) {
           
      $pageNum_sourceComments = $_GET['pageNum_sourceComments'];
          }
         
      $startRow_sourceComments = $pageNum_sourceComments * $maxRows_sourceComments;
          
         
      mysql_select_db($database_Del_Comments, $Del_Comments);
         
      $query_sourceComments = "SELECT
      c.sfk as sfk1,
      d.Memo as memo
      FROM
      asmanystatusupdate as c
      left join ascomments as d
      on d.id = c.cfk
      where c.uidfk0='1' and c.sfk in (
      $str_ids)";
         
      $query_limit_sourceComments = sprintf("%s LIMIT %d, %d", $query_sourceComments, $startRow_sourceComments, $maxRows_sourceComments);
         
      $sourceComments = mysql_query($query_limit_sourceComments, $Del_Comments) or die(mysql_error());
         
      $row_sourceComments = mysql_fetch_assoc($sourceComments);
          
          if (isset(
      $_GET['totalRows_sourceComments'])) {
           
      $totalRows_sourceComments = $_GET['totalRows_sourceComments'];
          } else {
           
      $all_sourceComments = mysql_query($query_sourceComments);
           
      $totalRows_sourceComments = mysql_num_rows($all_sourceComments);
          }
         
      $totalPages_sourceComments = ceil($totalRows_sourceComments/$maxRows_sourceComments)-1;
          
          
          
         
      $resultComments = @mysql_query($query_sourceComments, $Del_Comments);
         
      $numComments = @mysql_num_rows($resultComments);
          
          
         
      $result = @mysql_query($query_sourceType, $Del_Comments);
          
         
      $num = @mysql_num_rows($result);
          
         
      // column count for parent
             
      $thumbcols = 1;
          
                 
      // column count for parent query
             
      $thumbrows = 1+ round($num / $thumbcols);
          
                     
      // column count for child query    $thumbrowsComments = 1+ round($numComments/$thumbcols);
          
                      // header
                     
      print '<br />';
                      print
      '<table align="center" width="500" border="3" cellpadding="0" cellspacing="0">';
          
                      if (!empty(
      $num)) {
                          print
      '<tr><td colspan="3" align="center"><strong>Returned Num of Record Sets: ' .$num. ' and comments count' .$numComments. '</strong></td></tr>';   
          
                      }
          
             
      // table layout for parent query       
                
                function display_table() {
          
         
      // global variables
         
      global $num, $result, $thumbrows, $thumbcols, $resultComments, $numComments, $thumbrowsComments ;
          
         
      // row count for parent
          
      for ($r=1; $r<=$thumbrows; $r++) {
          
              
      // print table row
                  
      print '<tr>';
          
         
      //format the columns
         
      for ($c=1; $c<=$thumbcols; $c++) {
          
          print
      '<td align="center" valign="top">';
          
             
      $row = @mysql_fetch_array($result);
                $row1 = @mysql_fetch_array($resultComments);
          
             
      $Id = $row['Id'];
             
      $Type = $row['Type'];
             
      $Dates = $row['Dates'];
                $Comment = $row['Comment'];
                $Sfk1 = $row['sfk1'];
                $Memo = $row['memo'];

                
         
      // test if not empty show record sets           
             
      if (!empty($Id)) {
          
                                     
      // print output from parent query
          
                            
                                              // grab type dates comment and format for there column
          
                                             
      echo '<td valign="top" align="center">';
                                              echo
      "$Type"; echo '  '; echo "$Dates"; echo '<br />';echo '<br />';echo '<br />';
                                              echo
      "$Comment"; echo '</td>';
                                              echo
      '<td>'; echo "$Id"; echo '</td>';
                                              echo
      '<td>'; echo "$str_ids"; echo '</td>';
                     
                                 
                          echo '<tr>';
                                                             echo '<td>'; echo "$Sfk1"; echo '</td>';
                                                             echo '<td>'; echo "$Memo"; echo '</td>';
                                                             echo '</tr>';
                                                                  
                     } // closing the $id loop
          
                               
                                              
                                              
                                                          else {
                                                                  print
      '  ';
                                                              }
                                      print
      '</td>'; //closing the table data
                                 
      } //closing the rows
                                     
      print '</tr>';
                       }
      // closing the outter loop
                      //} //closing fk id loop
                                     
      print '</td>'; //closing the table data
                         
      } //closing the rows
                                     
      print '</tr>';   
                   
             
      //} // closing the main loop
          
                          // call the main table
                     
      display_table() ;
                          print
      '</table>';
          
          
         
      ?>

          
          
           <?php
      var_dump
      (substr('a', 1)); // bool(false)
      ?>