MySQL Forums
Forum List  »  PHP

JOIN 2 tables and pull information from each
Posted by: Charles Carter
Date: November 12, 2007 11:06AM

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:

<?
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>
<? } } ?>

Options: ReplyQuote


Subject
Written By
Posted
JOIN 2 tables and pull information from each
November 12, 2007 11:06AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.