yarub Posted September 29, 2006 Share Posted September 29, 2006 I'm trying to make it so that if I pull thirty rows from a database, they they go into three columns. However, I want them to begin a new row after they go through a column. I'm really bad at explaining stuff. Let's pretend I have thirty rows with incrementive numbers from one to thirty. I want it to do this when it pulls from the database:01 02 0304 05 0607 08 0910 11 1213 14 1516 17 1819 20 2122 23 2425 26 2728 29 30Does that make sense? I want a maximum of three columns. The more rows there are in the database, the more rows that would need to be made in the output. Can anyone direct me in the right way? Quote Link to comment https://forums.phpfreaks.com/topic/22451-make-query-start-new-row-after-three-columns/ Share on other sites More sharing options...
yarub Posted September 29, 2006 Author Share Posted September 29, 2006 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/22451-make-query-start-new-row-after-three-columns/#findComment-100704 Share on other sites More sharing options...
hostfreak Posted September 29, 2006 Share Posted September 29, 2006 Try this:[code]<?php$num = 1;$query = "SELECT * FROM table";$result = mysql_query($query) OR die(mysql_error()); while (($row = mysql_fetch_array($result)) && ($num >= 1)) { $field = $row['field']; if ($num == 1) { echo "<tr>"; } else if ($num == 4) { echo "</tr>"; $num = 1; } echo "<td>$field</td>"; $num++; }?>[/code]Your will need to modify the query table and the field. Quote Link to comment https://forums.phpfreaks.com/topic/22451-make-query-start-new-row-after-three-columns/#findComment-100710 Share on other sites More sharing options...
wildteen88 Posted September 29, 2006 Share Posted September 29, 2006 Could you post your current code here along with the query you're using too. I'll be able to adapt a code snippet of mine i used for another member to your needs. Quote Link to comment https://forums.phpfreaks.com/topic/22451-make-query-start-new-row-after-three-columns/#findComment-100728 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.