chuck1971 Posted November 13, 2007 Share Posted November 13, 2007 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> <? } } ?> Thanks for the help, All. I cannot express my appreciation here! Link to comment https://forums.phpfreaks.com/topic/77097-display-results-from-multiple-tables-with-php-and-mysql/ Share on other sites More sharing options...
bri0987 Posted November 13, 2007 Share Posted November 13, 2007 You have to connect to a database... ADD this line "mysql_select_db($database, $Db_connection);" Example: include("includes/connect.php"); mysql_select_db($database, $Db_connection); $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)) { ?> $database variable will look something like this: $database = "mysql_database_name_here"; $Db_connection will look like: $Db_connection = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); Link to comment https://forums.phpfreaks.com/topic/77097-display-results-from-multiple-tables-with-php-and-mysql/#findComment-390454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.