e1seix Posted September 9, 2007 Share Posted September 9, 2007 Quite a simple one really. If i execute a query in my php program that will return many results, how can i get it to divide the results between 3 seperate columns to display it. here's what i have so far but it just isn't working. Can anyone shed any light? <?php $fetch=mysql_query("SELECT * from fragrances WHERE avail='true'")or die(mysql_error()); $numrows=mysql_num_rows($fetch); $max = intval($numrows/3); if ($numrows%3) { // has remainder so add one page $max++; } $qry = mysql_query("SELECT * from logos WHERE avail='true' ORDER BY 'brand' LIMIT 0, $max")or die(mysql_error()); echo "<table><tr><td style='width:33%'>"; $i=0; while ($row = mysql_fetch_array($qry)) { if ($i > $max) { echo "<td style='width:33%'>"; $i=0; } echo '<div id="brand">'; echo '<a href="'.$_HTTPS['PHP_SELF'].''.$row['page'].'.php?sku='.$row['sku'].'">'; echo $row ['brand']; echo "</a></td>"; echo '</div>'; $i++; } echo "</td></tr>"; echo "</table>"; for example if the query returns 60 results (to make it easy), it will display first 20 results ($max) before if will then run a <td> tag to run the next 20 and again for the final 20. the <td> tags always 33% wide. Quote Link to comment https://forums.phpfreaks.com/topic/68636-displaying-query-results-in-3-colums/ Share on other sites More sharing options...
sasa Posted September 10, 2007 Share Posted September 10, 2007 try while ($row = mysql_fetch_array($qry)) { if ($i == 0) { echo "<td style='width:33%'>"; } echo '<div id="brand">'; echo '<a href="'.$_HTTPS['PHP_SELF'].''.$row['page'].'.php?sku='.$row['sku'].'">'; echo $row ['brand']; echo "</a>"; echo '</div>'; $i++; if ($i == $max){ echo '</td>'; $i = 0; } } Quote Link to comment https://forums.phpfreaks.com/topic/68636-displaying-query-results-in-3-colums/#findComment-345156 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.