Jump to content

columns rather than rows?


therelelogo

Recommended Posts

Hi,

 

having stopped php for a while, i'm a little rusty, can someone help me - instead of the results returning in a row by row format, can i have it so it returns column by column?

so, rather than result 1 being first, then 2 underneath then 3 etc etc, can i have result 2 next to result 1?

 

heres my code

 

$result = mysql_query("SELECT * FROM members ORDER BY member_id DESC")   
or die(mysql_error());  

echo "<table border='2'>";
echo "<tr> <th></th> <th></th> <th></th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row[printf('<img src="%s" height="96" width="128" style="border: 0" />', $row['profile_pic_short'])];
echo "</td><td>"; 
echo "<a href=\"PHP-Login/advert_pages/view_profile_specific.php?seller_name=$row[login]\">". $row['login'] . "</a>";
echo "</td></tr>"; 

} 

echo "</table>";
?>

 

all help appreciated

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/209276-columns-rather-than-rows/
Share on other sites

Would something like this be what you're after?

 

$i = 0;
echo "<tr>"; 
while($row = mysql_fetch_array( $result )) {
  if ($i % 5 == 0)
    echo "</tr><tr>";
  // Print out the contents of each row into a table
  echo "<td>"; 
  echo $row[printf('<img src="%s" height="96" width="128" style="border: 0" />', $row['profile_pic_short'])];
  echo "</td><td>"; 
  echo "<a href=\"PHP-Login/advert_pages/view_profile_specific.php?seller_name=$row[login]\">". $row['login'] . "</a>";
  echo "</td>"; 
  $i++
}
echo "</tr>";

 

-jm

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.