Jump to content

fetch_array in a table loop 3 columns per row


samtwilliams

Recommended Posts

Hi All,

 

I am trying to output some information from my sql database, I need to output three customers per row each in their own column (cell) and then after the 3rd customer start a new row etc etc.

 

I have the following code but there is a syntax error and i can't seem to find it, can someone point me the right direction.

 

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
  <tr class="headercolour">
    <td width="37%"><div align="center">
      <div align="left">><? echo $col1; ?></div>
    </div></td>
    
    <td width="39%"><div align="center">
      <div align="left"><? echo $col2; ?></div>
    </div></td>
    
    <td width="16%"><div align="center">
      <div align="left"><? echo $col3; ?></div>
    </div></td>
    </tr>
<?
i = 0;
while ($row = mysql_fetch_assoc($result))
{
if ($i == 0)
{
?>
<tr class="tr" onMouseOver="h(this)" onMouseOut="n(this)">
<?php } else { ?>
    <td><? echo $row['customername']; ?>test</td>
<?php
}
else ($i == 2)
{
	$i = 0;
?>
    </tr>
<?php
}
$i++;
}
?>
</table>

Thank you for your quick reply;

 

the $col variables where passed through from a different page using the post method, but I have now removed these. I do not recieve an error when running the page only that the page doesn't display anything.

 

Sam

try

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
  <tr class="headercolour">
    <td width="37%"><div align="center">
    <div align="left">><? echo $col1; ?></div>
    </div></td>
    
    <td width="39%"><div align="center">
    <div align="left"><? echo $col2; ?></div>
    </div></td>
    
    <td width="16%"><div align="center">
    <div align="left"><? echo $col3; ?></div>
    </div></td>
    </tr>
<?
i = 0;
while ($row = mysql_fetch_assoc($result))
{
if ($i++ == 0)
{
?>
<tr class="tr" onMouseOver="h(this)" onMouseOut="n(this)">
<?php    
           }  
?>
    <td><? echo $row['customername']; ?>test</td>
<?php if($i==3)	
           {
$i = 0;
?>
    </tr>
<?php
}
}
?>
</table>

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.