Keyword

Query to Return all Item Id's in same Category

More
10 years 7 months ago #125447 by Sean
I am trying to create a more robust Related Items section that will display in the item.php file. It is intended to be a new section and not change the default Related Items. I would like to display all items in the category, except the one being viewed.

My thoughts were I could do a table lookup using the current 'item id' to get the 'catid' value from the '#__k2_items" table.
// GET ID
$itemID = JRequest::getInt('id');

// Lookup Cat ID for Current Item
$db =& JFactory::getDBO();
$db->setQuery('SELECT catid FROM #__k2_items WHERE id="'.$itemID.'"');

// Load Category ID for Current Item
$itemCatID = $db->loadResult();

// Verify Category Id is being obtained - REMOVE AFTER
echo 'Category ID = '.$itemCatID.'<br/>';

So far so good, the correct 'catid' value is being displayed.

I would then query the same table to get all the 'item id' values that have the same 'catid' value (belong to same category). The problem I have is I an not familiar with how to make this query using Joomla coding practices.

I was hoping someone might be able to help understand how to write this query using Joomla coding practices. Any advice would be appreciated.

Once I can get the list of item id's I am quite comfortable with the rest.

Please Log in or Create an account to join the conversation.

More
10 years 7 months ago #125448 by Lefteris
Hi. What you try to achieve is not that simple. Even if you fetch the items you need to generate their links ( and possible other data you might require ). Also fetching all items from a category may kill your website if you have many items. Finally you also need to apply rules to your query regarding user access, publishing state etc. As you can see this is not a simple process for someone that is not a programmer. I suggest that you either hire a developer or search for a module that might do what you want.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum