Passing a variable from URL in query
2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 19, 2018 (RSS)
By ciaranmac - July 19, 2018
I have a multiple items and I want to list them out depending on the variable in the url.
Each item has a list of categories to chose which could be multiple ( Field name = video_category). I am passing this variable in the URL, so if the variable is 2, then I want every item with 2 selected for the field name 'video_category' to appear.
I can do it if I put the value in manually e.g. below:
// load records from 'videos'
list($videosRecords, $videosMetaData) = getRecords(array(
'tableName' => 'videos',
'where' => ' video_category LIKE "%\t2\t%" ', // contains 4
'loadUploads' => true,
'allowSearch' => false,
));
but I don't know what to do to pull the variable and put it in the query.
By leo - July 19, 2018
Hi,
Your url parameters will all be in the variable $_REQUEST. For example if you url looks like this: index.php?video_category=2, you will have this variable $_REQUEST['video_category'] equals 2. So your where statement can be something like this: 'video_category = "%\t' . $_REQUEST['video_category'] . '\t%"'. Note that if you didn't pass "video_category" parameter in the url and call $_REQUEST['video_category'], it will give you an error sayting $_REQUEST['video_category'] doesn't exist. So it's better to do an if(empty($_REQUEST['video_category'])) check before using it.
Let me know if you have any questions!
Thanks,
interactivetools.com