Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display query results within cells in table with multiple rows

Status
Not open for further replies.

ChocolateLover

Programmer
Jan 5, 2006
12
GB
Can anyone help please.

I'd like to create a table to display information from a query. The table has 4 columns, so the 5th record should be displayed in the 1st column of the 2nd row, the 9th record in the 1st column of the 3rd row, etc.

This is the code
Code:
//columns in the table
$columns=4;
$column_width=100/$columns;
<table width="100%" border="1" cellpadding="5" cellspacing="5" bordercolor="#FFFFFF">
                <tr>
                  <td height="30" colspan="1" class="newstitle"><div align="left"><?php echo $department_name; ?></div></td>
                </tr>
<?php				
do {
$cells=1;
?>
                <tr>
<?php
while ($cells<=$columns) {
	if ($row_retailer_list['retailer']==NULL) {
		$border_colour='FFFFFF';
		$retailer='&nbsp;';
	
	} else {
		$border_colour='B2B2B2';
		$retailer='<a href="' .  $_SERVER['PHP_SELF'] . '?select_retailer=' . $row_retailer_list['retailer_id'] . '"><p class="shoppingname">' . $row_retailer_list['retailer'] . '<br><span class="shoppinggrey">Please click here for shop details</span></p></a>';
	
	}
?>				
                  <td width="<?php echo $column_width; ?>%" height="60" bordercolor="#<?php echo $border_colour; ?>"><?php echo $retailer; ?></td>
<?php
	$cells++;
	$row_retailer_list = mysql_fetch_assoc($retailer_list); 
}
?>
                </tr>
<?php
echo 			$row_retailer_list['retailer'];	
} while ($row_retailer_list = mysql_fetch_assoc($retailer_list)); 
?>
</table>

The problem is that it's not displaying every 5th record as I'm skipping it by using $row_retailer_list = mysql_fetch_assoc($retailer_list) twice when I start a new row. Is there a function that moves the internal recordset pointer backwards? Or can someone suggest a better way of displaying the table?

Any help would be greatly appreciated.
 
You can control your output using TR and TD table tags.
Something like that

Code:
i=0
while ($row_retailer_list = mysql_fetch_assoc$retailer_list()) {
 if i=0 {
  <tr>
 }
 if ( i < 4 )
 {
  <td>
  i++
 }
 else {
  i=0
 </tr>
 }
}


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
there was a recent thread asking for a similar thing.
thread434-1168385
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top