Joining Tables

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

Re: [Illume Magazine] Joining Tables

By gregThomas - December 3, 2012

Hi,

I think you can use the leftJoin setting in the getRecords function to retrieve the data from the user_submissions table and user_profiles table at the same time, something like this should work:

// load records from 'shop_categories'
list($user_profiles, $profilesMetaData) = getRecords(array(
'tableName' => 'user_profiles',
'loadUploads' => true,
'allowSearch' => false,
'leftJoin' => array(
'user_submissions' => 'ON user_profiles.user_id = user_submissions.user_id'
)
));


So the leftJoin array pulls secondary data from the user_submissions table, where the user_profiles user_id value matches the user_submissions user_id value.

Alternatively a simpler way to do it might be to have two getRecords functions that pull the data from each table individually, using something like this:

$userID = 43; //Set the user_ID value to this variable

// load records from 'user_submissions'
list($user_submissions, $user_submissionsMetaData) = getRecords(array(
'tableName' => 'user_submissions',
'loadUploads' => true,
'allowSearch' => false,
'where' => "user_id = '$userID'"
));

// load records from 'user_profiles'
list($userProfiles, $userProfilesMeta) = getRecords(array(
'tableName' => 'user_profiles',
'loadUploads' => true,
'allowSearch' => false,
'where' => "user_id = '$userID'"
));



Thanks

Greg
Greg Thomas







PHP Programmer - interactivetools.com