Jump to content

How to display three different records in one row


Stefbug

Recommended Posts

Hi,

I've been trying to work this one out for ages.

I am calling data from a database, and displaying it using a while loop:

[code]<?php
while($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
?>

<table>

<tr>
<td width="320px"><a href="<?php echo $row['img_url'] ?>" target="_blank"><img src="<?php echo $row['img_url']; ?>" height="200" /></a></td>
</tr>

<tr class="submain"> 
<td width="150px"><?php echo $row['full_name']; ?></td>
</tr>

<tr class="submain">
<td width="150px"><?php echo $row['description'];?></td>
</tr>
<?php    
}
?>
</table>[/code]

This works just fine, and displays a table that has one record per row (each record has 3 pieces of data: img_url, full_name and description that display one under another):

-----------
|record 1 |
-----------
|record 2 |
-----------
etc.

However I would like to be able to display this data in a table like this:

-------------------------------
|record 1 | record 2 | record 3|
-------------------------------
|record 4 | record 5 | record 6|
-------------------------------

etc.

Any help you could offer would be most appreciated.

Thanks in advance.

Stef
Not sure what you are looking for here, do you want all the information in one row for each record? The code above puts
the information into three rows. I a very new to PHP but this is something that I might do, code is not tested.

[code]
<?php

//Start row count at 0
$row_count = 0;


//Start your table
echo"<TABLE border ='1'><TR>\r";
while($row = mysql_fetch_array($query, MYSQL_ASSOC)) {

//Check row_count to see if there should be a new table row made or and col.
if ($row_count < 2) {

//See if there are no more records, if not put in the blank col.
if ($row['img_url'] == "") {
echo "<td></td>\r";
}else{
echo "<td width=\"320px\"><a href=\"".$row['img_url']>"\" target=\"_blank\"><img src=\"">$row['img_url']."\" height=\"200\"/></a></td>";
echo "<td width=\"150px\">".$row['full_name']."</td>";
echo "<td width=\"150px\">".$row['description']."</td>";

}

//Increment row_count by 1
$row_count++;
  }else{
  if ($row['img_url'] == "") {
echo "<td></td></tr><tr>";
}else{
echo "<td width=\"320px\"><a href=\"".$row['img_url']>"\" target=\"_blank\"><img src=\"">$row['img_url']."\" height=\"200\"/></a></td>";
echo "<td width=\"150px\">".$row['full_name']."</td>";
echo "<td width=\"150px\">".$row['description']."</td>";
        echo"</TR><tr>\r";
}
   
//
$row_count = 0;
  }
}
?>
[/code]
Hope that helps you out in some way

Cheers!
Stephen

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.