"Where" syntax for multiple choice

13 posts by 4 authors in: Forums > CMS Builder
Last Post: March 5, 2013   (RSS)

By gregThomas - March 5, 2013

Hi,

If the user is an administrator, then you won't need a where statement as all of the results need returning. I would do something like this: 

<?php

if(@$CURRENT_USER['isAdmin']){
  //If the user is an admin, no where statement is needed as we are returning all results
  $where = '';
}else{
  //Else, find out which teams they should be able to see
  //Trim will remove the tab space at the beginning of the list. The team values will be tab separated, explode them into an array
  $values = explode("\t",trim($CURRENT_USER['team']));
  //implode the values into a comma seperated array
  $values = implode(',',$values);
  $where = "(team_1 IN($values))";
}

//The MySQL IN statement will retrieve any rows which appear in the $values list.
list($gamesRecords, $gamesMetaData) = getRecords(array(
  'tableName'   => 'games',
  'loadUploads' => true,
  'where' => $where,
  'allowSearch' => false,
  'perPage'     => '18',
));

This is just test code, so you might need to make a few changes to get it working.

So if the user is an admin, then we set the $where variable to nothing. But if the user is a normal user, we find there team, and get the values from it and store that in the $where string.

The where string is set against the where key in the getRecords function. 

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Codee - March 5, 2013

Greg,

I've tested your code with a couple small changes and it works very well. Thank you VERY much! I will work this in for this client!