Jump to content


Sorting mysql data into 2 columns

  • Please log in to reply
1 reply to this topic

#1 tsiedsma

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 10 March 2006 - 08:04 PM

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]

#2 mem0ri

  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 10 March 2006 - 09:04 PM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users