seran128 Posted November 14, 2006 Share Posted November 14, 2006 ok I have three tables the first table holds the category NameSomthing liketbl_categoryCategoryIDCategory NameThe second table holds news information Something liketbl_newsNewsID (int)News Title (varchar80)News Content (blob)The third table joins the two tablestbl_news_join_categoryID (INT)NewsID (INT)CategoryID (INT)this way I can have a news article belong to many different Categories okmy function[code]function news(){ global $connection; $sql="select * from tbl_category"; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $news .= "<table width='200' border='0'> <tr> <td>" . stripslashes($row['category_name']) . "</td> </tr> <tr> <td></td> </tr> </table>";} return $news}[/code]This returns the category name as it should now what I would like to do is do a query after the [code]<td>" . stripslashes($row['category_name']) . "</td>[/code]and display all the news titles that belong to that categorythen continue onwith the rest of the code [code]</tr> <tr> <td></td> </tr> </table>";} return $news}[/code] Link to comment https://forums.phpfreaks.com/topic/27184-nested-sql-statements/ Share on other sites More sharing options...
The Little Guy Posted November 14, 2006 Share Posted November 14, 2006 [code]<?phpfunction news(){ global $connection; $sql="select * from tbl_category"; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $news .= "<table width='200' border='0'> <tr> <td>" . stripslashes($row['category_name']) . "</td>"; $sqls = mysql_query("SELECT * FROM tbl_news WHERE category='$row[category_name]'") or die(mysql_error()); while($rows=mysql_fetch_array($sqls)) { echo $rows['column_name_from_tbl_news']; } echo" </tr> <tr> <td></td> </tr> </table>";} return $news}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27184-nested-sql-statements/#findComment-124324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.