Feature records in one table using accounts table

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

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 4cdg - January 12, 2015

in the user accounts table i have created a checkbox inside the cms called featured listings.

I have a table created called Equipment where different users have author access to enter different records they want to display on the site.

On the home page of the website we are showing around 15 random records from the equipment table.

what i wanted to be able to do is inside the cms, user accounts table was check the box i created call featured listings and on the home page of the website, only show listings authored by users who have the checkbox checked.

Right now i can show 15 random of all the listings in the equipment table, but would like to know how to limit it to only the users who are checked  featured.

so i guess this is in the front end and inside the cms....

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/