Jump to content

[SOLVED] Using ober's multi-column display with two tables


agent99max

Recommended Posts

I was reading ober's post in the snippets (http://www.phpfreaks.com/forums/index.php/topic,95426.0.html),

and was wondering if someone could give me some direction on using that with two tables. I want to the data to break across columns as they flow top to bottom (newspaper style).

 

What I have only produces one long column.

<?php
	$query = "select * from category";
	$result = mysql_query($query);

	 while($row = mysql_fetch_array($result)) {
		$categoryid = $row['id'];
		$categoryname = $row['category'];
			$query2 = "select * from advertisers where category_id='$categoryid' and active=1";
			$result2 = mysql_query($query2);

	 if(mysql_num_rows($result2) > 0 ) {
		 echo "<h1>".$categoryname."</h1>";
			while($row2 = mysql_fetch_array($result2)) {
			$advertisername = $row2['name'];
		 echo "Showcase for ".$advertisername. "<br />";
   		   }
      } else {
    	  echo "No advertisers found for this category.";
   			   } 
      }
?>

 

I am not sure how to get my stuff from the two tables into a single query. I was told that I could not use joins for what I'm trying to accomplish, and am quite new to this.

 

Thanks,

max

This will give newspaper style columns

 

http://www.phpfreaks.com/forums/index.php/topic,207411.msg942688.html#msg942688

 

SELECT c.categoryid, c.categoryname, a.name
FROM category c LEFT JOIN advertiser a ON c.categoryid = a.category_id

 

a.name will be NULL if there are no advertisers for a category

 

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.