Jump to content

split database output into different columns


advancedfuture

Recommended Posts

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>';
?>

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.