Jump to content
Larry Ullman's Book Forums

Problem Printing Table Info


Recommended Posts

Hi,

 

I want to display a table of interest groups in a html table. My loop prints out a new row, which is fine. The problem I have is that I want my table to print 4 columns i.e. the <td> tag four times. I am not sure of the code to repeat the <td> tag four times.

 

Any ideas would be gratefully accepted. Here is my code for the moment.

 

<table class="data-table">
 
<?php do { ?>
  <tr>
      <td><a href="#"><?php echo $rs_display_groups['GroupName']; ?></a></td>      
  
<?php } while ($rs_display_groups = mysqli_fetch_array($display_groups_result)); ?> 
   </tr> 
                                      
</table>    
 
 
Link to comment
Share on other sites

Sorry code should read:

 

<table class="data-table">
 
<?php do { ?>
  <tr>
      <td><a href="#"><?php echo $rs_display_groups['GroupName']; ?></a></td>   
  </tr> 
<?php } while ($rs_display_groups = mysqli_fetch_array($display_groups_result)); ?> 
                                      
</table>  
Link to comment
Share on other sites

This is easily enough done once you understand the logic. Before the loop, create a counter variable that goes from 1 to 4. Initialize it to 1, before the loop. Within the loop (looping through the results), first check if the counter equals 1. If so, create a new row (a

). Then print the record within a . Then increment the counter. Then check if the counter equals 4 (i.e., the row is done). If so, close the and reset the counter to 1. 

 

That takes care of the display of records. After the loop, you'll need to go from the counter to 4 to create the required

s to complete the last row, and close the last . 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...