josephman1988 Posted August 30, 2008 Share Posted August 30, 2008 Hey guys So yea, basically the entries that are being selected and joined then printed is being displayed 3 times (each category)rather then the once needed <?php $sqlgd = mysql_query("SELECT guidesgamesconnect.gamesgId, guides.guId, guides.guTitle, guides.guName, guides.guAuthor, guides.guDate, guides.guVersion FROM guidesgamesconnect, guidescategoriesconnect LEFT JOIN guides, guidescategories ON guides.guId = guidesgamesconnect.guidesguId WHERE guidesgamesconnect.gamesgId = $gId and guidescategoriesconnect.guidescategoriesgcId = '1' ") or die(mysql_error()); while ($sqlq = mysql_fetch_array($sqlgd)) { print " <div id='manageall'> <div id='managetop'> <strong>Title:</strong> " . $sqlq['guTitle'] . "<br /><strong>Version:</strong> " . $sqlq['guVersion'] . " </div> <div id='managebot'> [ <a href='guides/" . $sqlq['guName'] . "' >View</a> ] <div class='ad'><strong>Author:</strong> " . $sqlq['guAuthor'] . "<br /> <strong>Date:</strong> " . $sqlq['guDate'] . "</div> </div> </div> "; } ?> Tables: gamecategories ====================== | gcId | gcName | ====================== | 1 | Walkthroughs | | 2 | In-Depth Guides | | 3 | Codes/Cheats | ====================== gamecategoriesconnect ============================ |guidesguId | guidescategoriesgcId | ============================ |10 | 1 | ============================ Any insight would be great. Link to comment https://forums.phpfreaks.com/topic/122002-displaying-data-in-categories/ Share on other sites More sharing options...
BlueSkyIS Posted August 30, 2008 Share Posted August 30, 2008 while looping over the records, keep track of which category is currently being displayed. when a category comes up that isn't the current category, print the new category and continue with the same logic. Link to comment https://forums.phpfreaks.com/topic/122002-displaying-data-in-categories/#findComment-629743 Share on other sites More sharing options...
josephman1988 Posted August 30, 2008 Author Share Posted August 30, 2008 while looping over the records, keep track of which category is currently being displayed. when a category comes up that isn't the current category, print the new category and continue with the same logic. How would I keep track of the currently displayed category? Is the JOIN query correct? Because if we ignore my question, it was already a join query connecting the guide to the game, now wanting to connect the guide to the category I think that's where Im getting confused. Original query before trying to 'categorize' it: SELECT guidesgamesconnect.gamesgId, guides.guId, guides.guTitle, guides.guName, guides.guAuthor, guides.guDate, guides.guVersion FROM guidesgamesconnect LEFT JOIN guides ON guides.guId = guidesgamesconnect.guidesguId WHERE guidesgamesconnect.gamesgId = $gId Link to comment https://forums.phpfreaks.com/topic/122002-displaying-data-in-categories/#findComment-629867 Share on other sites More sharing options...
Barand Posted August 30, 2008 Share Posted August 30, 2008 How would I keep track of the currently displayed category? Store it. sample pseudocode: prev = ''; // current category while fetch next record if category not equal prev print new category set prev = new category end if print detail end while You need to order the query output by category Link to comment https://forums.phpfreaks.com/topic/122002-displaying-data-in-categories/#findComment-629984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.