PHP Results into two columns

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

PHP Results into two columns

Post by ianhull »

Hi Guys,

How would I sort my results into a table with two colmns,

I am looping though records in a MySQL DB and echoing out the results but I could really do with the results being layed out in two columns.




Code:

Code: Select all

<table width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td colspan="2" align="left" valign="top">'.$module.'</td>
  </tr>
  <tr>
    <td width="5%" align="left" valign="top"><img src="'.$image.'"></td>
    <td width="95%" align="left" valign="top">'.$description.'</td>
  </tr>
</table>
is what I currently have
and below is what I really need out.


Code:

Code: Select all

<table width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td colspan="2" align="left" valign="top">'.$module.'</td>
    <td colspan="2" align="left" valign="top">'.$module.'</td>
  </tr>
  <tr>
    <td width="5%" align="left" valign="top"><img src="'.$image.'"></td>
    <td width="31%" align="left" valign="top">'.$description.'</td>
    <td width="5%" align="left" valign="top"><img src="'.$image.'"></td>
    <td width="59%" align="left" valign="top">'.$description.'</td>
  </tr>
</table>
here is my php


PHP Code:

Code: Select all

<?php 

include_once("includes/connect.php"); 
$myemail = $_SESSION['myemail']; 
$sql = "SELECT email, module, level, image FROM security WHERE email='$myemail' ORDER BY module ASC"; 
$r = mysql_query($sql); 
if(!$r) { 
$err=mysql_error(); 
print $err; 
exit(); 
} 
if(mysql_affected_rows()==0){ 
echo 'No Modules Available.'; 
exit(); 
} 
else{ 
echo '<table width="100%" cellspacing="2" cellpadding="2">'; 
} 
while ($line = mysql_fetch_array($r))     
{ 
extract($line); 
echo '<tr> 
    <td width="2%"><img src="images/'.$image.'" alt="'.$module.'"></td> 
    <td width="98%" class="Navigation">'.$module.'</td> 
  </tr>'; 
} 
echo '</table>'; 
?>
Thanks for any help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have a look at the first two links in Useful Posts.
Post Reply