Jump to content

Displaying data in categories


josephman1988

Recommended Posts

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

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.