Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.