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.
Results 1 to 4 of 4
  1. #1
    Regular Coder optimus203's Avatar
    Join Date
    Sep 2008
    Location
    CT
    Posts
    317
    Thanks
    22
    Thanked 16 Times in 15 Posts

    Insert <hr> after every 6th mysql_fetch_array row

    I have a mysql_fetch_array result that produces 120 or so rows. To help make the resulting table more readable, I would like to insert a <hr>, or some graphic, after every 6th row of the resulting table. Any ideas how to do so? Here's the code I've got for the mysql_fetch_array.

    Code:
    echo '<table class="db_t_res">\n';
    
    if($result) 
    {
      while($row = mysql_fetch_array($result)) 
      {
      echo '<tr>\n
            <td style="width:10%;">'.
       echo $row['year'];
    	echo '</td>\n
    	      <td style="width:30%;">';
    	echo $row['industry'];
    	echo '</td>\n
    	      <td style="width:60%;">';
    	echo $row['emissions'];
    	echo '</td>\n
    	      </tr>\n';
      }
    }
    
    echo '</table>\n';
    Always thank those CF Users who help you solve issues...
    Connecticut Web Design

  • #2
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    PHP Code:
    <?php
    echo '<table class="db_t_res">\n';

    if(
    $result) {
        
        
    $i 0/* var */
        
    while($row mysql_fetch_array($result)) {
          
            if(
    $i==6) { 
                echo 
    '<tr><td colspan="3"></td></tr>'
                
    $i=0;
            }
            echo 
    '<tr>\n
            <td style="width:10%;">'
    ;
            echo 
    $row['year'];
            echo 
    '</td>\n
            <td style="width:30%;">'
    ;
            echo 
    $row['industry'];
            echo 
    '</td>\n
            <td style="width:60%;">'
    ;
            echo 
    $row['emissions'];
            echo 
    '</td>\n
            </tr>\n'
    ;
        
            
    $i++; //inc $i
        
        
    }
    }

    echo 
    '</table>\n';
    ?>
    untested
    Last edited by met; 03-20-2010 at 05:35 PM.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    PHP Code:
    echo '<table class="db_t_res">\n';

    if(
    $result
    {
    $i=0;
      while(
    $row mysql_fetch_array($result)) 
      {
      
    printf"<tr %s>\n
            <td style=\"\">"
    ,($i%6==0?'class="hr"':''));
       echo 
    $row['year'];
        echo 
    "</td>\n
              <td style=\"width:30%;\">"
    ;
        echo 
    $row['industry'];
        echo 
    "</td>\n
              <td style=\"width:60%;\">"
    ;
        echo 
    $row['emissions'];
        echo 
    "</td>\n
              </tr>\n"
    ;
        
      }
    }

    echo 
    '</table>\n'
    Code:
    tr.hr td{
    background:#ccc;
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    scratch that, use abduraoofts version !


  •  

    Posting Permissions

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