Pulling records from multiple tables

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

By (Deleted User) - December 8, 2010

Hi Guys,

I'm trying to pull records from my 'featured' table so that they display in a single list with my 'news' table records. They both have the same category num which is '1'.

What I'm trying to create is an archives list with 10 records per page but pulling records from two different tables.

This is what I currently have in my code:

list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'news',
'tableName' => 'featured',
'tableName' => 'categories',
));

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


Is this possible?

Regards
Shawn

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