Home | Products | Consulting | Forums | Support | Order | 1-800-752-0455
  Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Using category num in URL

 

 


IronVictory
User

Jun 19, 2008, 9:30 AM

Post #1 of 6 (228 views)
Shortcut
Using category num in URL Can't Post

I am calling this page productList?cat=1 to show all products within a particular category. I have two questions:
1) The fieldname is actually called "category". Can I use "cat" instead of "category" in the URL? How do I relate "cat" to "category" so the page only shows the category =1 products?
2) Category =1 is actually "Tents". How can I convert the num of "1" into "Tents"?


Dave
Staff / Moderator


Jun 19, 2008, 9:55 AM

Post #2 of 6 (225 views)
Shortcut
Re: [IronVictory] Using category num in URL [In reply to] Can't Post

Hi IronVictory,

1) The simplest way would be to rename your field from 'category' to 'cat'. Another way would be to add this line just below require_once ...


Code
  require_once "../lib/viewer_functions.php"; 

$FORM['category'] = @$FORM['cat'];


What that does is copy the 'cat' value to 'category'. The extra @ hides an error that would be displayed if 'cat' wasn't defined.

2) If you store categories by name instead of num, you can actually just search for ?category=Tents. The only downfall to that is if you rename the "Tents" category then all the records will not be linked up to it anymore. If that's not a problem then storing the value by name is the easiest way.

The next (more complicated) way is to use a second viewer to get all the record numbers from your category section that match "tents" and then use a 'where' to only return products in one of those category nums.

Hope that helps, let me know if you have more questions about any of that.

Dave Edis - Senior Developer
interactivetools.com


IronVictory
User

Jun 19, 2008, 10:05 AM

Post #3 of 6 (224 views)
Shortcut
Re: [Dave] Using category num in URL [In reply to] Can't Post

Hi Dave,
Sorry, could you show me how the second viewer would look?
I am confused (which doesn't take much) on how to use the variable (category) in the 'where'


Dave
Staff / Moderator


Jun 19, 2008, 11:36 AM

Post #4 of 6 (210 views)
Shortcut
Re: [IronVictory] Using category num in URL [In reply to] Can't Post

I can, is it possible to store the category names instead of nums though? Or do you not want to use that method?

Dave Edis - Senior Developer
interactivetools.com


IronVictory
User

Jun 19, 2008, 12:08 PM

Post #5 of 6 (208 views)
Shortcut
Re: [Dave] Using category num in URL [In reply to] Can't Post

I prefer to use nums, so if "Tents" ever changes to "Family Tents", etc. it won't break.


Dave
Staff / Moderator


Jun 19, 2008, 4:15 PM

Post #6 of 6 (182 views)
Shortcut
Re: [IronVictory] Using category num in URL [In reply to] Can't Post

Ok, here's how you get the category number that matches "Tents". Just have the category fieldname and value in the url. eg: viewer.php?name=Tents If you don't want it to say name you can use the trick above.


Code
  // get category num (put this below require_once) 
list($categoryRecords) = getRecords(array(
'tableName' => 'category',
'allowSearch' => true,
'requireSearchMatch' => true,
));
$categoryNum = @$categoryRecords[0]['num'];


Next, just print out the categoryNum while testing to make sure you're getting the right value:


Code
// print categoryNum to make sure we have the right one 
print "<h1>categoryNum: $categoryNum</h1>";


Finally, add a where to your viewer (this one is for news). Also, set allowSearch = false so you the products will ignore the search keywords and only show products in the selected category num.


Code
// 
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'allowSearch' => false,
'where' => "category = '$categoryNum'",
));


Hope that helps, let me know if you have any problems with any of that.

Dave Edis - Senior Developer
interactivetools.com

 
 
 


Search for (options)
Products
CMS Builder
Article Manager
Realty Manager
Listings Manager
Order Now
Services
Priority Consulting
Support
Online Documentation
Support Forums
Support Homepage
Company Info
12 reasons to choose us!
Meet the team
Monthly newsletter
Contact Us
Toll Free: 1-800-752-0455
Phone: (604) 689-3347
Sales | Support
Conditions of Use | Privacy Policy | Copyright © interactivetools.com 2008
#201 - 2730 Commercial Drive, Vancouver BC Canada V5N 5P4