anthelo Posted March 5, 2011 Share Posted March 5, 2011 i have 2 tables. table 1 - Id -Name -ShortId table 2 -lots of data.... -Category (same value with table1 Id) im trying to join this 2 tables... $query = "SELECT * FROM tblnews_categories WHERE ShortId != 0 ORDER BY `ShortId`"; $result = mysql_query($query); $query2 = "SELECT * FROM tblnews_categories, tblnews WHERE tblnews_categories.Id = tblnews.Category "; $result2 = mysql_query($query2); while($row = mysql_fetch_assoc($result)) { ?> <div class="quartetin2"> <div id="HomeMoreNewsIMG2"><div id="HomeMoreNewsTitle2"><a href="summary?catid=19167"><?php echo strtoupper($row['Name']);?></a></div></div> <div id="HomeMoreNewsText"> <?php while($row2 = mysql_fetch_assoc($result2)) { ?> <tr> <td id="HomeLatestNewsDate"><li><?php echo strtoupper($row2['Title']);?></li></td> </tr> <?php } ?> What i want to do is when Id = Category echo all data under the specific category Quote Link to comment https://forums.phpfreaks.com/topic/229663-joining-2-tables-need-help/ Share on other sites More sharing options...
Fergal Andrews Posted March 5, 2011 Share Posted March 5, 2011 Hi anthelo, SELECT tblnews .*, tblnews_categories.* FROM tblnews INNER JOIN tblnews_categories ON table_news.id=tblnews_categories.id cheers, Fergal Quote Link to comment https://forums.phpfreaks.com/topic/229663-joining-2-tables-need-help/#findComment-1183289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.