SQL Search Question
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 11, 2011 (RSS)
By everbatim - March 10, 2011
I need to use the SQL "where" statement to filter results from 2 different fields (from the same table). What I'm trying to do is check all the records of a certain table and only return results that match either field. I tried using an "or" statement, however that just renders the search useless. I can successfully narrow the results searching only 1 field, but not when I add the OR statement where I think it should go.
So, I have a multi-record table, called WEBINARS which contains many fields. I want the page to search the PRESENTER field AND CO_PRESENTER field (both are simple lists) and only display records that match a single presenter name. Here is the code I tried, which does not work.
Any thoughts? Again, I want to search 2 fields for the same value and only return the matching results.
Thanks in advance!
So, I have a multi-record table, called WEBINARS which contains many fields. I want the page to search the PRESENTER field AND CO_PRESENTER field (both are simple lists) and only display records that match a single presenter name. Here is the code I tried, which does not work.
list($webinarsRecords, $webinarsMetaData) = getRecords(array(
'tableName' => 'webinars',
'allowSearch' => '0',
'where' => 'Presenter="name1"' or 'Co_Presenter="name1"',
));
Any thoughts? Again, I want to search 2 fields for the same value and only return the matching results.
Thanks in advance!
Re: [everbatim] SQL Search Question
By Jason - March 11, 2011
Hi,
You're really close. You need to have the "or" inside the string, otherwise you're using a php "or", not a MySQL "or".
Try this:
Hope this helps
You're really close. You need to have the "or" inside the string, otherwise you're using a php "or", not a MySQL "or".
Try this:
list($webinarsRecords, $webinarsMetaData) = getRecords(array(
'tableName' => 'webinars',
'allowSearch' => '0',
'where' => "Presenter='name1' OR Co_Presenter='name1' ",
));
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/