samtwilliams Posted February 24, 2009 Share Posted February 24, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/146653-fetch_array-in-a-table-loop-3-columns-per-row/ Share on other sites More sharing options...
DEVILofDARKNESS Posted February 24, 2009 Share Posted February 24, 2009 Where is the code that generates $col, $col2, ... ? and can you show us the error? Quote Link to comment https://forums.phpfreaks.com/topic/146653-fetch_array-in-a-table-loop-3-columns-per-row/#findComment-769928 Share on other sites More sharing options...
samtwilliams Posted February 24, 2009 Author Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146653-fetch_array-in-a-table-loop-3-columns-per-row/#findComment-769929 Share on other sites More sharing options...
sasa Posted February 24, 2009 Share Posted February 24, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/146653-fetch_array-in-a-table-loop-3-columns-per-row/#findComment-769994 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.