Help with Search. Very Urgent, please help!

5 posts by 3 authors in: Forums > CMS Builder
Last Post: April 27, 2009   (RSS)

By dsn7287 - April 25, 2009

Ok I guess this is pretty straight forward problem.

In my list viewer page I use php get to get some values into some variables like so:
$quick_option = $_GET['varQuickOption'];
$start_date = $_GET['varStartdate'];
$end_date = $_GET['varEnddate'];
$match_type = $_GET['varType'];
$team_type = $_GET['varTeam'];

the problem I have is I want to be able to use these variables in the list viewers 'where' clause like so:

list($fixturesRecords, $fixturesMetaData) = getRecords(array(
'tableName' => 'fixtures',
'where' => 'match_type = $match_type',
'perPage' => '15',
));

However I am having no luck. This gave me the error:
getRecords(fixtures) MySQL Error: Unknown column '$match_type' in 'where clause'

I have tried putting it like this: "$match_type", this '$match_type' and even this echo($match_type) but nothing works!

Could anyone provide me with a solution please? Any help would be VERY VERY much appreciated.

Cheers

Re: [dsn7287] Help with Search. Very Urgent, please help!

By Dave - April 25, 2009

Hi dsn7287,

Variables only get replaced with their values in double quoted strings, so what you want is this:
'where' => "match_type = '$match_type'",

Except for security, you want to escape any input from the web so users can't pass SQL commands to your server (this is called SQL Injection - google for more details). Here's how to prevent that:
'where' => "match_type = '" .mysql_real_escape_string($match_type) ."'",

But another simpler option might be to use the built in search features described here: http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html and just do this:

yourViewer.php?match_type=MatchValue

Instead of passing the value in varType in the url, just pass it in match_type and it will automatically do what you want.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [dsn7287] Help with Search. Very Urgent, please help!

By ross - April 27, 2009

Hi there.

Just wanted to make sure everything is moving along. It sounds like Dave's post got your going again but if you are still having trouble with anything, let me know :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Help with Search. Very Urgent, please help!

By dsn7287 - April 27, 2009

MAte everything right on track... Wroking like a charm... Dave's code definitely gave me the direction... The information on the fourm has been invaluable in me being able to continue... Thanks to all the contributors!