agent99max Posted July 29, 2008 Share Posted July 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/117215-solved-using-obers-multi-column-display-with-two-tables/ Share on other sites More sharing options...
Barand Posted July 29, 2008 Share Posted July 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/117215-solved-using-obers-multi-column-display-with-two-tables/#findComment-602986 Share on other sites More sharing options...
agent99max Posted July 29, 2008 Author Share Posted July 29, 2008 Thanks - I'll give that a try. max Link to comment https://forums.phpfreaks.com/topic/117215-solved-using-obers-multi-column-display-with-two-tables/#findComment-603009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.