Displaying records by category
2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 9, 2013 (RSS)
By rui - February 8, 2013
Hi from Portugal,
I´m doing a newspapper website with categorys.
I have a normal Multi Category with:
- Title
- Text
- Photo
- Category - list type (Sport - International - Regional - European)
In the home page i dont have a problem, i´m showing all the categories, the problem is when i have to show only 1 categories.
For ex: I create a new file (sport.php) and i want to show all records that have the item "sport" selected.
// load records from 'news'
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'loadUploads' => true,
'allowSearch' => false,
));
What i need is some type of ('where' => category=sport, )... sorry my programing skills are terrible.
Can someone help me??
tks
Rui
By Dave - February 9, 2013
Hi Rui,
Try this:
// load records from 'news'
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'loadUploads' => true,
'allowSearch' => false,
'where' => " category LIKE '%sport%' ",
));
If you have multi value fields, you may a few values selected and stored in the field like this "sport european" so a simple " category = 'sport' " test will fail.
In MySQL LIKE is the same as equals but it lets you use wildcards % which mean (Matches any number of characters, even zero characters) so LIKE "%sport%" means "Match anything that has the word "sport" in it, even if there is other content before or after it.
Hope that helps, Let me know if that works for you.
interactivetools.com