If less than X records

6 posts by 3 authors in: Forums > CMS Builder
Last Post: January 13, 2009   (RSS)

Hi, and happy new year!

Is it possible to write an IF statement saying:

IF there are less than 4 records in the table...

For example:
<?php if ($productsRecords QUANTITY < 4): ?>

Many thanks in advance
Rob

Re: [rjbathgate] If less than X records

By aev - January 13, 2009

Re: [rjbathgate] If less than X records

By Dave - January 13, 2009

Hi Rob,

You can check the record meta details (as suggested above) or the array count directly like this:

<?php if (count($productsRecords) < 4): ?>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] If less than X records

Excellent, thanks... although upon implementing it I realised I need another criteria...

The productsRecord have a field 'Display' (with answers Yes/No).

It needs to be an IF statement whereby count of records with Display = Yes is less than 4.

Is the easiest way to run another call of the productsRecord list with a where display=yes clause, and then run the count within that?

i.e.

<?php
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => " online = 'Yes'",
?>

<?php if (count($productsRecords) < 4): ?>


That will work won't it? The count of less than 4 will be running from this new listing of only where records are online yes?

Fingers crossed...

Thanks again

Re: [Dave] If less than X records

Yes, sorry my mistake, Display is actually Online.

Working a treat with the above code, thanks again