Jump to content

Sorting mysql data into 2 columns


tsiedsma

Recommended Posts

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

[code]
<?
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)
  $count++;

//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>";    

}

mysql_free_result($result);

mysql_close();

?>
[/code]

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]
Link to comment
https://forums.phpfreaks.com/topic/4632-sorting-mysql-data-into-2-columns/
Share on other sites

Sounds like a simple HTML formatting issue...

[code]
<table>
     <tr>
          <td>data1</td>
          <td>data2</td>
     <tr>
<!--Repeat for as many rows as you like with those two columns-->
</table>
[/code]

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

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.