coupe-r Posted December 25, 2009 Share Posted December 25, 2009 Hello All. Here is what I have: Client ID Company name Client ID Company name I then need a script to echo 2 results per row then start a new row. I've tried many things, but never could get a second row to appear. Each row will have 4 columns. Here is my code without the "guts" My vars will be $id and $company. $result = mysql_query("SELECT * FROM client"); if(mysql_num_rows($result) < 1) { $results = 'You have 0 clients.'; } else { $results = ''; $results .= '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">'; $results .= '<tr>'; while($row = mysql_fetch_array($result)) { } $results .= '</table>'; } Link to comment https://forums.phpfreaks.com/topic/186347-loop-column-after-2-results/ Share on other sites More sharing options...
rajivgonsalves Posted December 25, 2009 Share Posted December 25, 2009 something like this should work <?php $result = mysql_query("SELECT * FROM client"); if(mysql_num_rows($result) < 1) { $results = 'You have 0 clients.'; } else { $results = ''; $results .= '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">'; $results .= '<tr>'; $i=1; while($row = mysql_fetch_array($result)) { if ($i%2 == 0) echo "</tr><tr>"; echo "<td>" . $row['fieldname'] . "</td>"; $i++; } $results .= '</tr></table>'; } ?> Link to comment https://forums.phpfreaks.com/topic/186347-loop-column-after-2-results/#findComment-984050 Share on other sites More sharing options...
coupe-r Posted December 25, 2009 Author Share Posted December 25, 2009 Thanks for the reply. I had something like that before, but here is what it echos 10001 Company 1 10002 Disney Inc. 10004 a It should only have 10001 and 10002 on that link and then a seperate line for 10004, but it does not create a new row. Here is the code now: $results = ''; $results .= '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">'; $results .= '<tr>'; $i=1; while($row = mysql_fetch_array($result)) { if ($i%2 == 0) { echo "</tr><tr>"; } $results .= "<td>".$row['client_id']."</td>"; $results .= "<td>".$row['client_company']."</td>"; $i++; } $results .= '</tr></table>'; Link to comment https://forums.phpfreaks.com/topic/186347-loop-column-after-2-results/#findComment-984054 Share on other sites More sharing options...
rajivgonsalves Posted December 25, 2009 Share Posted December 25, 2009 it should have been <?php $results = ''; $results .= '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">'; $results .= '<tr>'; $i=0; while($row = mysql_fetch_array($result)) { if ($i%2 == 0) { $results .= "</tr><tr>"; } $results .= "<td>".$row['client_id']."</td>"; $results .= "<td>".$row['client_company']."</td>"; $i++; } $results .= '</tr></table>'; ?> Link to comment https://forums.phpfreaks.com/topic/186347-loop-column-after-2-results/#findComment-984057 Share on other sites More sharing options...
coupe-r Posted December 25, 2009 Author Share Posted December 25, 2009 PERFECT. Thank you very much for the quick replies. Link to comment https://forums.phpfreaks.com/topic/186347-loop-column-after-2-results/#findComment-984059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.