show only specific items based on variable

9 posts by 4 authors in: Forums > CMS Builder
Last Post: December 8, 2009   (RSS)

I am using a link similar to this to show only items in a category: productList.php?category=4. How do i show only items that are in this category keeping in mind that the category variable changes. Can I put a variable in a 'where' clause?

Re: [IronVictory] show only specific items based on variable

By Dave - June 12, 2008

There are two ways to limit the results shown on the page. You can add 'where' clause such as:

'where' => ' category="4" ',

Or add values on the end of the url to use the built in search features (see search docs) like you did:

productList.php?category=4

The second method is often the easiest. Are you listing categories on the page that links to the above url? If so you can create a link like this:

productList.php?category=<?php echo $categoryRecord['num']; ?>

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] show only specific items based on variable

hi Dave,I guess my main problem is how do I show only items from the specific category on the list page if the category id changes? I want to use one productList.php page, not separate pages for each category.

Re: [IronVictory] show only specific items based on variable

By Dave - June 12, 2008

Let me make sure I understand correctly. Let me know if this right. You have a single product list page (productList.php) and you want it to show products from only a single category at a time? Is that right?

You should be able to do that by just always linking to the page with the category number dynamically added to the end like this:

productList.php?category=2
productList.php?category=44
etc.

Why would the category id change? Do you want to always show items from one category and then optionally show items from another category on the same page?

Are you able to post an url that shows what you want the output to look like? Sorry if I'm not understanding... If you can provide some more details I'll try and help out.
Dave Edis - Senior Developer
interactivetools.com

Re: [IronVictory] show only specific items based on variable

By Dave - June 12, 2008

It does that automatically by default. If you put a fieldname from the CMS in the url with a value it will add that to the where clause. For example, if you have a field called 'category' then this url:

productList.php?category=2
Automatically adds this to the where clause 'category = 2'.

productList.php?content_keyword=hello
Automatically adds this to the where clause 'content LIKE "%hello%"'.

There some more documentation on how the searching features work here:
http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

You only need to manually specify the where clause when you're trying to do something advanced.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] show only specific items based on variable

Boy does that ever help. Thank you!

Re: [IronVictory] show only specific items based on variable

Hello,

I have read all the information above and understand the process of using ONE record at the end of the URL so that we can use one php file (say productList.php) for various product category listings. However, I am not clear on the linking pages you mentioned Dave. This also ties in with creating dynamic content to match the URL category (a Page Heading for example).

Since most web pages include a heading at the top of the page content, ( for example - Our Products: Toys) how do we include the dynamic category name (Toys) at the top of the pages so that it matches the dynamic category field within the URL?

It would be nice to use only ONE listing.php file and have the heading match. Sure, we can make separate Listing.php pages, but that means more work. Your help is greatly appreciated.

Thanks,

studio-a

Re: [studio-a] show only specific items based on variable

By Chris - December 8, 2009

Hi studio-a,

Let's say you have two sections: Categories and Products. You could have a page called categoryList.php which has one link per category to productList.php?category=123, where 123 is the category record number.

Inside productList.php, you can load the appropriate category record:

list($categoryRecords, $categoryMetaData) = getRecords(array(
'tableName' => 'category',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$categoryRecord = @$categoryRecords[0]; // get first record


...AND the product records for that category:

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
));


You can extract the name of the category (e.g. $categoryRecord['title'] which might be "Our Products: Toys") to customize your page's heading, then list the products below.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris