Pulling records from multiple tables

6 posts by 4 authors in: Forums > CMS Builder
Last Post: December 10, 2010   (RSS)

Re: [smesa] Pulling records from multiple tables

By Jason - December 8, 2010

Hi Shawn,


You could try using 2 different queries:


// load news
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'perPage' => '5',
'where' => "category = '1'",
'allowSearch' => true,
));

// load featured
list($featuredRecords, $featuredMetaData) = getRecords(array(
'tableName' => 'featured',
'perPage' => '5',
'where' => "category = '1'",
'allowSearch' => true,
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Pulling records from multiple tables

By (Deleted User) - December 8, 2010

Thanks Jason - sorry I was thinking. I got it working now.

Kind regards
Shawn

Re: [smesa] Pulling records from multiple tables

By Jason - December 9, 2010

Hi Shawn,

Glad to hear everything is working now.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Pulling records from multiple tables

Jason -

How would you merge the output into one "list", so that...

// load news
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'perPage' => '5',
'where' => "category = '1'",
'allowSearch' => true,
));

// load featured
list($featuredRecords, $featuredMetaData) = getRecords(array(
'tableName' => 'featured',
'perPage' => '5',
'where' => "category = '1'",
'allowSearch' => true,
));


in effect becomes...

$featurednewsRecords

...or something similar?

:o/

Perch

Re: [Perchpole] Pulling records from multiple tables

By Chris - December 10, 2010

Hi Perch,

You can use the array_merge() function to do this:

$allRecords = array_merge($newsRecords, $featuredRecords);

You can add as many arrays to the array_merge() call as you need.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris