Jump to content

[SOLVED] adjusting cell or row height in a table within php while loop


coolphpdude

Recommended Posts

Hi guys,

 

I am outputting pictures into a gallery page using a while loop.

 

// thumbnail table
echo "<table width='100%' border='0' cellspacing='0' cellpadding='10'>";

//set number of columns and initial column number
$numcols = 3; // how many columns to display
$numcolsprinted = 0; // no of columns so far

// get the results to be displayed
$query = "SELECT * FROM pics WHERE pic_id='$id'";
$mysql_result = mysql_query($query) or die (mysql_error());

// get each row
while($myrow = mysql_fetch_array($mysql_result))
{
	//get data 
	$pic = $myrow[0];

	if ($numcolsprinted == $numcols) 
	{
		print "</tr>\n<tr height ='500'>\n";
		$numcolsprinted = 0;
	}
	$pic_name = $myrow["vp_thumb"];
	$pic_id = $myrow["vp_id"];

	// output row from database
	echo "<td width='300' height='500' align='center' valign='top'><img src='$pic_name' border='0'></td>\n";

	// bump up row counter
	$numcolsprinted++;

} // end while loop

$colstobalance = $numcols - $numcolsprinted;
	for ($i=1; $i<=$colstobalance; $i++) {

	}
print "<TD height ='500'></TD>";
echo"</table>";

 

The  while loop works great. it outputs all of my thumbnails into a 3 column table. the problem i am having is when it outputs the next row of pictures. The next row is actually directly under the first row (i.e not a single pixel between the picture in the first row and the second row. Any idea's why it is doing this?? as you can see i've tried adding height='500' to both the <td> tags and the <tr> tag>.

 

Cheers

i've got the cell padding which you see within <table> tag. Im a little confused with this because i am sure the html should produce spacing with the settings i have above. I may have put this loop together wrong which is creating the problem but i cant seem to spot where i am going wrong!

You cant set the height of <tr> you need to set the height of <td>. Also Cell padding is the amount of padding between the cell inside wall and what ever is in it and cell spacing is the amount of spacing between cells.

cell padding/spacing should only be set within the opening table tag. You cannot set cell padding/spacing within the TD tags.

 

To space table rows out you should set cellspacing, eg

   echo "<table width='100%' border='0' cellspacing='10' cellpadding='0'>";

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.