Page 1 of 1

Display results from multiple tables with php and mysql

Posted: Mon Nov 12, 2007 9:59 pm
by chuck1971
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have two tables, one table (article_cat) has four fields ("id", "title", "feature1", and "feature2") and the other table has six fields (articles) has ("id", "cat_id", "title", "content", "feature1", and "feature2"). I am looking to display the "title" from the "article_cat" table that has "feature1" with a value of 1. And I want to display beneath that all the "title" results from the "articles" table where "feature1" has a value of 1. I have tried this a thousand ways with no luck. Here is a representation of what I want:

TITLE (article_cat)
title (articles)
title (articles)
title (articles)

I was hoping someone can show me the err of my ways. Thanks so much in advance to all those who help! Here is the flawed code I have thus far:

Code: Select all

<?
include("includes/connect.php");
$query = mysql_query("SELECT * FROM articles, article_cat WHERE articles.feature1 = 1 AND article_cat.feature1 = 1 ORDER BY id ASC");
$numrows=@mysql_num_rows($query);
if($numrows != 0) {
while ($result = mysql_fetch_array($query)) {
?>
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"><strong><? echo $result['article_cat.title']; ?>:</strong><br>
<strong>></strong><a href="article_details.php?id=<? echo $result['id']; ?>"><? echo $result['articles.title']; ?></a><br>
</td>
</tr>
</table>
</td>
</tr>
<? } } ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]