anthelo Posted March 6, 2011 Share Posted March 6, 2011 Hi, im trying to echo some mysql data. What i want to do is under a category show the articles that is for the specific category have a look at my attachment, the blue is where the categorys titles and below is supposed to show the different articles for the specific category. Here is my code <div class="NewsCateg"> <div class="NewsCategBG"> <?php $query = "SELECT * FROM tblnews_categories WHERE ShortId != 0 ORDER BY `ShortId`"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { ?> <div class="quartetin2"> <div id="HomeMoreNewsIMG2"><div id="HomeMoreNewsTitle2"><a href="summary.asp?catid=19167"><?php echo strtoupper($row['Name']);?></a></div></div> <div id="HomeMoreNewsText"> <?php $query2 = "SELECT tblnews.Category, tblnews.Title, tblnews_categories.Id FROM tblnews LEFT JOIN tblnews_categories ON tblnews.Category = tblnews_categories.Id"; $result2 = mysql_query($query2); while($row2 = mysql_fetch_assoc($result2)) { ?> <tr> <td id="HomeLatestNewsDate"><li><?php echo strtoupper($row2['Title']);?></li></td> </tr> <?php } ?> </div> </div> <?php } ?> </div> </div> Any help please? Thank you [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/229794-problem-displaying-data-for-every-category-seperetly/ Share on other sites More sharing options...
jcbones Posted March 6, 2011 Share Posted March 6, 2011 You have a quite a bit of HTML errors in there. You are putting table rows inside of a division. If you wish to use table rows, you must make a table first. You are also creating line items without a list of the ordered or un-ordered type. As far as the PHP goes, you need to ORDER BY tblnews.Category, then check the category against the last one pulled, if it is the same, display it, otherwise start a new box. Quote Link to comment https://forums.phpfreaks.com/topic/229794-problem-displaying-data-for-every-category-seperetly/#findComment-1183658 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.