Jump to content


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


Sorting mysql data into 2 columns

Recommended Posts

I have some data in a database I want to display in 2 columns. How can I accomplish this?

include 'dbax.php';

$result = mysql_query("SELECT * FROM locations ORDER BY name ASC");
$myrow = mysql_fetch_array($result);
if (!$result) {
   die('Could not view record:' . mysql_error());
if ($myrow = mysql_fetch_array($result)) {

$itemsPerRow = 2;
$count = 0;

while($row = mysql_fetch_array($result)) {
  if ($count % $itemsPerRow == 0)

//echo <td> tags and array $row[whatever] data  here.

echo "</table>";
} else {

    echo "<p><strong>There is currently no information in the database.</strong></p><br>";    





I have 9 rows I need displayed for each group. I want the groups of data to be 2 across and 2 or 3 rows down. I would also like to add a next link or button to view the next group of data.

Here is a quick example of what I am wanting it to look like:
[a href=\"http://img163.imageshack.us/my.php?image=image1tm.gif\" target=\"_blank\"][img src=\"http://img163.imageshack.us/img163/1310/image1tm.th.gif\" border=\"0\" alt=\"IPB Image\" /][/a]

Share this post

Link to post
Share on other sites
Sounds like a simple HTML formatting issue...

<!--Repeat for as many rows as you like with those two columns-->

Since getting data from the database doesn't seem to be an issue for you, I'll leave that part to you.

Share this post

Link to post
Share on other sites


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.