jakebur01 Posted March 7, 2009 Share Posted March 7, 2009 I am trying to create a "browse members" page. This page will display thumbnails in a table about 4 columns wide. I am not sure what the best way to set up the table would be. I am not sure how to count and loop through 4 <td>'s and then insert the <tr> tag. How would you do this? Like: <table width=100%> select username, nickname, image_link FROM user_table while { } </table> Quote Link to comment https://forums.phpfreaks.com/topic/148361-solved-displaying-members-in-a-table/ Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Basics are here:- <table width=100%> <?php $sSql = "select username, nickname, image_link FROM user_table"; if ( !($result = mysql_query($sSql)) ) { $rowNum = 0; while( $row = mysql_fetch_assoc($result) ) { echo (($rowNum % 4 == 0) ? "<tr>" : "")."<td><img src='".$row['image_link']."' /></td>".(($rowNum % 4 == 3) ? "</tr>" : ""); $rowNum++; } } ?> </table> You will really need to clean up and finish off a row after the loop (ie, if the total number of users is not divisible by 4 this would leave half a row at the end). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148361-solved-displaying-members-in-a-table/#findComment-778906 Share on other sites More sharing options...
jakebur01 Posted March 7, 2009 Author Share Posted March 7, 2009 Hi Keith, Would you just check to see how many blank rows are needed to make 4? And then insert like 4 <td> </td>'s ? Quote Link to comment https://forums.phpfreaks.com/topic/148361-solved-displaying-members-in-a-table/#findComment-778913 Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Yep Or do something like:- if (($rowNum % 4) > 0) { while (($rowNum % 4) > 0) { echo "<td> </td>"; $rowNum++; } echo "</tr>"; } All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148361-solved-displaying-members-in-a-table/#findComment-778918 Share on other sites More sharing options...
jakebur01 Posted March 7, 2009 Author Share Posted March 7, 2009 Thank you. Keith Quote Link to comment https://forums.phpfreaks.com/topic/148361-solved-displaying-members-in-a-table/#findComment-778931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.