working with WHERE clause
2 posts by 2 authors in: Forums > CMS Builder
Last Post: May 3, 2011 (RSS)
By kovali - May 3, 2011
Hi,
Situation: news items can be posted into 3 categories: VW News - Audi News - Skoda News
Problem: my customer wants to display only the latest news-item of each category on the frontpage of the website, like:
VW News
Latest VW news article goes here...
Audi News
Latest Audi news article goes here...
Skoda News
Latest Skoda news article goes here...
With the WHERE clause I can filter on 1 category, like:
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="Audi"',
'limit' => '1',
This is okay for one category, but how can this be done for all 3 categories ??
Any help appreciated, thanks!
Koen
Situation: news items can be posted into 3 categories: VW News - Audi News - Skoda News
Problem: my customer wants to display only the latest news-item of each category on the frontpage of the website, like:
VW News
Latest VW news article goes here...
Audi News
Latest Audi news article goes here...
Skoda News
Latest Skoda news article goes here...
With the WHERE clause I can filter on 1 category, like:
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="Audi"',
'limit' => '1',
This is okay for one category, but how can this be done for all 3 categories ??
Any help appreciated, thanks!
Koen
Re: [kovali] working with WHERE clause
By gkornbluth - May 3, 2011
Hi Koen,
The simplest that I can think of is just to repeat the "get records" call on the viewer and use different where criteria for each.
So...
<?php
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="Audi"',
'limit' => '1',
?>
Audi News
Latest Audi news article goes here...
<?php
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="Skoda"',
'limit' => '1',
?>
Skoda News
Latest Skoda news article goes here...
<?php
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="VW"',
'limit' => '1',
?>
VW News
Latest VW news article goes here...
The wheres can be as simple or as complex as required, and you can use 'orderBy' to change the order in each call if required.
Give it a try...
Jerry Kornbluth
The simplest that I can think of is just to repeat the "get records" call on the viewer and use different where criteria for each.
So...
<?php
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="Audi"',
'limit' => '1',
?>
Audi News
Latest Audi news article goes here...
<?php
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="Skoda"',
'limit' => '1',
?>
Skoda News
Latest Skoda news article goes here...
<?php
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'category="VW"',
'limit' => '1',
?>
VW News
Latest VW news article goes here...
The wheres can be as simple or as complex as required, and you can use 'orderBy' to change the order in each call if required.
Give it a try...
Jerry Kornbluth
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php