Jump to content

Split query into two table columns


nepzap2

Recommended Posts

ok guys

 

I have a query that pretty much retrieves staff contact data from the database and echo's it out in a table with 1 row and 4 columns. What  I'm trying to do is split the returned data into two tables right next to each other  both with 1 row and 4 columns. Any help is greatly appreciated.

 

Code:

<?php

		//WHERE category='Affiliate'

		include 'db_config.php';
		$sql = "SELECT * 
				FROM staff_contact_table 
				WHERE active = 1
				ORDER BY last_name";	   
		$result = mysql_query($sql);

	?>
        <?php
		while ($row = mysql_fetch_assoc($result)) {

		$name = $row['first_name'];
		$last_name = $row['last_name'];
		$title = $row['title'];
		$office = $row['office'];
		$lab = $row['lab'];
		$officeTel = $row['office_phone'];
		$labTel = $row['lab_phone'];
		$url = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $row['url']);
		$email = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $row['email']);
		$title = $row['title'];



		echo "<table>
				<tr>
					<td><b>$last_name, $name</b></td>
					<td>Office/Lab $office, $lab</td>
					<td>Office/Lab Tel # $officeTel, $labTel</td>
					<td>Email: <a href='mailto:$email@cornell.edu'>$email@cornell.edu</a></td>

				</tr>
			   </table>";


		}


		?>

Link to comment
Share on other sites

Try this:

<?php
	$i=0;
         while ($row = mysql_fetch_assoc($result)) {
                        
         $name = $row['first_name'];
         $last_name = $row['last_name'];
         $title = $row['title'];
         $office = $row['office'];
         $lab = $row['lab'];
         $officeTel = $row['office_phone'];
         $labTel = $row['lab_phone'];
         $url = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $row['url']);
         $email = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $row['email']);
         $title = $row['title'];
         $align = ($i%2) ? "right" : "left"; //switch right and left for odds and evens. Starts on Left
      

         echo "<table width=\"49%\" align=\"$align\">
               <tr>
                  <td><b>$last_name, $name</b></td>
                  <td>Office/Lab $office, $lab</td>
                  <td>Office/Lab Tel # $officeTel, $labTel</td>
                  <td>Email: <a href='mailto:$email@cornell.edu'>$email@cornell.edu</a></td>
                  
               </tr>
               </table>";
      
              $i++;//Incriment i 
         }
         
         
         ?>

Link to comment
Share on other sites

Sorry, got playing with it, it won't work...

Retry:

<?php
echo "<table width=\"100%\">\n<tr>\n";
$r=0;
$c=0;
while ($row = mysql_fetch_assoc($result)) {
$name = $row['first_name'];
$last_name = $row['last_name'];
$title = $row['title'];
$office = $row['office'];
$lab = $row['lab'];
$officeTel = $row['office_phone'];
$labTel = $row['lab_phone'];
$url = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $row['url']);
$email = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $row['email']);
$title = $row['title'];
if($c==1){ $c=0; echo "</tr>\n<tr>"; }
echo "<td><table>
               <tr>
                  <td><b>$last_name, $name</b></td>
                  <td>Office/Lab $office, $lab</td>
                  <td>Office/Lab Tel # $officeTel, $labTel</td>
                  <td>Email: <a href='mailto:$email@cornell.edu'>$email@cornell.edu</a></td>
                  
               </tr>
               </table></td>";
	$c++;
}
echo "</tr></table>";
?>

Link to comment
Share on other sites

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.