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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.