Category Quickie!
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 30, 2010 (RSS)
By Perchpole - March 30, 2010
Hello, All -
I'm using $selectedCategoryNum = @$_REQUEST['category']; to pull in the URL category - which obviously returns a number.
Ideally I'd also like to display the title of the category as a header somewhere on the page.
However if I echo $selectedCategoryNum I'll just get a number.
So, what would be the most efficient way to derive the corresponding title of the category from the returned number?
(NB: I'm currently using a foreach loop coupled with getlistlabels - which works but seems a bit OTT to display a single header!)
:os
Perch
I'm using $selectedCategoryNum = @$_REQUEST['category']; to pull in the URL category - which obviously returns a number.
Ideally I'd also like to display the title of the category as a header somewhere on the page.
However if I echo $selectedCategoryNum I'll just get a number.
So, what would be the most efficient way to derive the corresponding title of the category from the returned number?
(NB: I'm currently using a foreach loop coupled with getlistlabels - which works but seems a bit OTT to display a single header!)
:os
Perch
Re: [Perchpole] Category Quickie!
By Jason - March 30, 2010
Hi,
First, we need to set up a database query:
You may have to change the tableName depending what you call the category table.
Then, you can use this code anywhere below that query:
Again, you may need to change the word "title" depending on what the field is called in you database. You can also changed the HTML to format it however you want.
Hope this helps.
First, we need to set up a database query:
<?php
list($categoryRecords,$categoryMetaData)= getRecords(array(
'tableName' => 'category',
'where' => 'num='.$selectedCategoryNum,
'limit' => '1'
));
?>
You may have to change the tableName depending what you call the category table.
Then, you can use this code anywhere below that query:
<?php echo "<h2>".$categoryRecords[0]['title']."</h2>"; ?>
Again, you may need to change the word "title" depending on what the field is called in you database. You can also changed the HTML to format it however you want.
Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/