Combining getRecords Calls?
2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 3, 2013 (RSS)
By Perchpole - October 2, 2013
Hello, All
Is it possible to combine multiple, similar getRecords calls?
I've been creating a lot of margin widgets to show links to different articles on a site. One might show a list of links to 5 records in the same section as the current record. Another might show the latest 5 records in all sections, etc, etc...
The getRecords calls used to generate these lists is almost identical. The only thing that changes is the where clause:
list($relatedRecords) = getRecords(array(
'tableName' => 'records',
'where' => " parenNum = $record['parentNum'] ",
'limit' => '5'
));
list($newsRecords) = getRecords(array(
'tableName' => 'records',
'where' => " category = 7 ",
'limit' => '5'
));
list($latestRecords) = getRecords(array(
'tableName' => 'records',
'where' => 'date >= DATE(NOW())',
'limit' => '5'
));
Cycling through all of the records on the site 3 times seems to be a waste of overhead. Is there a way to combine the getRecords calls - or do something similar?
:0s
Perch
Hi Perch,
If you wanted to you could get all of the records using one getRecord call, and then filter the results using foreach loops, if statements and array groupBy. But I don't think it would speed up page loads significantly, and it would make the code a lot more difficult to read. I would just leave the code as you currently have it as it's nice and clear, and let MySQL do the complicated sorting stuff. :-)
Cheers!
Greg
PHP Programmer - interactivetools.com