Jump to content

[SOLVED] displaying members in a table


jakebur01

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/148361-solved-displaying-members-in-a-table/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.