advancedfuture Posted November 6, 2008 Share Posted November 6, 2008 So I am spitting out a large amount of data from my database, and I want to group it in columns that have only 15 records per column. So far I havent had much success. This is my code, what am I doing wrong? <?php $query = "SELECT DISTINCT city FROM `zip_code` WHERE state_name='$state' ORDER BY city ASC"; $results = mysql_query($query); $num = mysql_num_rows($results); echo '<table width="820" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF"><tr>'; for ($counter = 1; $counter <= 15; $counter++) { echo '<td>'; while($row = mysql_fetch_array($results)) { $city = $row['city']; //GLOBAL RESUME echo '<li>'; echo '<a href="city.php?st='.$state.'&city='.$city.'">'.$city.'</a>'; echo"</li>"; } echo '</td>'; } echo '</tr></table>'; ?> Link to comment https://forums.phpfreaks.com/topic/131714-split-database-output-into-different-columns/ Share on other sites More sharing options...
advancedfuture Posted November 7, 2008 Author Share Posted November 7, 2008 no one Link to comment https://forums.phpfreaks.com/topic/131714-split-database-output-into-different-columns/#findComment-684204 Share on other sites More sharing options...
ILMV Posted November 7, 2008 Share Posted November 7, 2008 I'll take this one... You shouldn't be looping through the records x amount of times, you should limit the amount of records in SQL. For example... SELECT * from orders WHERE city = 'new york' LIMIT 15; this will return only 15 records from orders. You can also do LIMIT 30,15, this will start your limit at the 30th record, with a limit length of 15. Read here for a bit more info http://php.about.com/od/mysqlcommands/g/Limit_sql.htm ILMV Link to comment https://forums.phpfreaks.com/topic/131714-split-database-output-into-different-columns/#findComment-684210 Share on other sites More sharing options...
advancedfuture Posted November 7, 2008 Author Share Posted November 7, 2008 Well see thats the thing, I dont want JUST 15 records, I want them all, but I want them to be returned in a nice format rather than a mile long page of results. :-\ Link to comment https://forums.phpfreaks.com/topic/131714-split-database-output-into-different-columns/#findComment-684222 Share on other sites More sharing options...
ILMV Posted November 7, 2008 Share Posted November 7, 2008 Right you're going to need to confirm this to me, which do you want... 1) Have all records stretching down the page, but with column headers every 15 records 2) Have only 15 records displayed If its none of these, if you can explain more, give an example or draw a diagram that would be good ILMV Link to comment https://forums.phpfreaks.com/topic/131714-split-database-output-into-different-columns/#findComment-684228 Share on other sites More sharing options...
advancedfuture Posted November 7, 2008 Author Share Posted November 7, 2008 option #1 is my goal good sir Link to comment https://forums.phpfreaks.com/topic/131714-split-database-output-into-different-columns/#findComment-684232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.