View Single Post
Old 09-25-2002, 07:53 AM   PM User | #1
Candrias77
Regular Coder

 
Join Date: Jul 2002
Location: New Zealand
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Candrias77 is an unknown quantity at this point
Display Data in Two Columns

I am fairly new to php and mySQL so forgive me if this is a basic question.

I have a page of data that is coming out of the database formatted into table cells running down the page. I am wanting to display this in two columns, say if there were 11 entries, have 6 going down on the left and then 5 going down the right.

I presume i need to count them in some way and when more than half of them have been displayed enter some code to end the column and start the next one, then display the rest.

Any idea how to do this?

The code i am currently using is here:



PHP Code:
<?
require("../local.inc.php");
?>

<html>
<head>

<?
$sql 
"SELECT * FROM applicators WHERE region = '$region' ORDER BY company_name ";
$result mysql_query($sql$db) or user_error('Dang');
if (
mysql_num_rows($result) > 0) {
?>

</head>
<body bgcolor="#ffffff" text="#000000">

<br>

<table width="100%" border="0" cellspacing="0" cellpadding="10">
 <tr> 
  <td><b><font color="#B64000" size="3"> 
   <? echo ($region?>
   </font></b></td>
  <td align="right"><a href="applicators_region1.htm">Back to city list</a></td>
 </tr>
 <tr> 
  <td colspan="2"> 
   <table border="0" width="100%" cellspacing="1" cellpadding="3">
  <?
  
while ($row mysql_fetch_assoc($result)) {
  
?>
    <tr> 
     <td> <b> 
      <? echo $row['company_name'?>
      </b><br>
      <? if ($row['applicator_name']) { ?>
      <i> 
      <? echo $row['applicator_name'?>
      </i><br>
      <? ?>
      <? if ($row['address']) { ?>
      <? echo $row['address'?>
      <br>
      <? ?>
      <? if ($row['phone']) { ?>
      Ph: 
      <? echo $row['phone'?>
      <br>
      <? ?>
      <? if ($row['fax']) { ?>
      Fax: 
      <? echo $row['fax'?>
      <br>
      <? ?>
      <? if ($row['mobile']) { ?>
      Mobile: 
      <? echo $row['mobile'?>
      <br>
      <? ?>
      <? if ($row['email']) { ?>
      <a href="mailto:<? echo $row['email'?>">Email</a><br>
      <? ?>
      <? if ($row['website']) { ?>
      <a href="http://<? echo $row['website'?>" target="_blank">Website</a> 
      <? ?>
     </td>
    </tr>
    <?
  
}
  }
  else
  {
  
?>
    <tr> 
     <td colspan="8">No applicators found.</td>
    </tr>
   </table>
  <?
  
}
  
?>
  </td>
 </tr>
</table>

</body></html>


Thanks.
__________________
eTheory - the theory of revolution
Candrias77 is offline   Reply With Quote