Feature records in one table using accounts table

6 posts by 2 authors in: Forums > CMS Builder
Last Post: January 12, 2015   (RSS)

By 4cdg - January 8, 2015

I have a table called equipment where multiple users add records to the database.

I would like to feature some users equipment records on a page while other users records i don;t want to include

I created a checkbox in the accounts table that says feature equipment.  When i check this i would like to be able to display all the records that user has authored in the equipment table.

so say i have 30 users and want to feature 6 users equipment listings, how would i set the filter for that.

By claire - January 9, 2015

Okay, is this in the front end or inside the CMS?

--------------------

Claire Ryan
interactivetools.com

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

By claire - January 12, 2015

Okay good, this is likely more simple than it seems. Can you copy the getRecords call for the 15 random records here please?

--------------------

Claire Ryan
interactivetools.com

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

By 4cdg - January 12, 2015

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/usr/local/www/dewittslist.com/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'equipment'
list($equipmentRecords, $equipmentMetaData) = getRecords(array(
'tableName' => 'equipment',
'limit' => '15',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,
));

?>

By claire - January 12, 2015

Okay, please look at these changes:

load($users, $usersMeta) = getRecords(array(
'tableName' => 'users',
'where' => 'featured = 1',
'allowSearch' => false,
'loadUploads' => false
));
$featuredIds = array_pluck($users, 'num');

// load records from 'equipment'
list($equipmentRecords, $equipmentMetaData) = getRecords(array(
'tableName' => 'equipment',
'limit' => '15',
'where' => 'user IN ('.mysql_escape(implode(',',$featuredIds)).')',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,
));

Please make sure you change the table name in the first getRecords to the name of the relevant user table, and change the variable name in the where parameter in the second getRecords to whatever it should be for the user num.

--------------------

Claire Ryan
interactivetools.com

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