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
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

Link to comment
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.