display only certain results

3 posts by 3 authors in: Forums > CMS Builder
Last Post: November 27, 2012   (RSS)

Hi,
How can i create some code to only retrieve certain results on a page. For example i want to display a list of articles that are in a partivular 'category/"
Jeff Saitz

Re: [jeffsaitz] display only certain results

Hi jeffsaitz,

There are a number of easy ways to determine what will be displayed on a page, and there are a large number of options available for each method.

One way is to use "if" statements that check for a condition and based on that condition display some information.

So if you only wanted to display a list of records for a specific category, you could use something like:
<?php foreach ($your_tableRecords as $record): ?>
<?php if ($record['your_category_field_name'] == 'your_category'): ?>
<<a href="<?php echo $record['_link'] ?>/><?php echo $record['your_article_title_field'] ?></a><br />
<?PHP endif ?>
<?php endforeach; ?>


You could also limit the information that can be displayed in other ways, like using a where statement in the load records code at the top of the page

list($your_tableRecords, $your_tableMetaData) = getRecords(array(
'tableName' => 'your_table',
'where' => " your_category_field_name = 'your_category' ",

));

Or if you want the visitor to be able to determine what is shown, you could use a simple search form on your page.
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="text" name="your_field_name_match" value="">
<input type="submit" name="submit" value="Search">
</form>


There's a lot more that can be accomplished with each of these methods, and you'll find a lot of implementation recipes in my CMSB Cookbook http://www.thecmsbcookbook.com

Hope that helps,

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