Page 2 of 2
Posted: Sat Aug 13, 2005 11:09 am
by Ambush Commander
You must quote strings inside the SQL.
Code: Select all
"SELECT `foo` FROM `bang` WHERE name = %s"
becomes
Code: Select all
"SELECT `foo` FROM `bang` WHERE name = Foobar"
Which is incorrect, it should be:
Code: Select all
"SELECT `foo` FROM `bang` WHERE name = 'Foobar'"
sorry
Posted: Sat Aug 13, 2005 8:42 pm
by olm75
no change at all
Posted: Sat Aug 13, 2005 8:43 pm
by feyd
what did you change?
ok
Posted: Sun Aug 14, 2005 1:37 am
by olm75
i think my problem mostly lies in the query itself...this is what i have:
Code: Select all
SELECT venuename, address, city, `state`, zip, phone, areacode
FROM venues_new
WHERE venuename LIKE 'MMColParam%' AND areacode = 'varAC'
but what i want to do is allow the viewer to search with 1 or any combination of fields in the search form...to get results or narrow results, what this query is doing is making them choose both fields without having the option to choose just one...if they want a much broader search....and i have 4 more list/menu search fields to add on....
here is the form:
http://www.nightspotz.com/search1.php
Posted: Sun Aug 14, 2005 1:41 am
by John Cartwright
Code: Select all
$query_rsSearch = sprintf("SELECT venuename, address, city, `state`, zip, phone, areacode FROM venues_new WHERE venuename LIKE '%%s%' AND areacode = '%s'", $MMColParam_rsSearch,$varAC_rsSearch);
Notice the change in
...venuename LIKE '%%s%' AND area.....
Edit | Feyd's way is the correct way

Posted: Sun Aug 14, 2005 1:45 am
by feyd
*cough*
Code: Select all
$query_rsSearch = sprintf("SELECT venuename, address, city, `state`, zip, phone, areacode FROM venues_new WHERE venuename LIKE '%%%s%%' AND areacode = '%s'", $MMColParam_rsSearch,$varAC_rsSearch);

excuse me

.. I must get rid of this dastardly cold. ooo.
i'm sorry
Posted: Sun Aug 14, 2005 2:53 am
by olm75
how will that translate to this:
Code: Select all
SELECT venuename, address, city, `state`, zip, phone, areacode
FROM venues_new
WHERE venuename LIKE 'MMColParam%' AND areacode = 'varAC'
Posted: Sun Aug 14, 2005 7:27 am
by feyd
it doesn't.
Posted: Sun Aug 14, 2005 9:13 am
by Ambush Commander
By the way, the backticks that I had in my SQL is just a little habit I picked up from analyzing PHPMyAdmin dumps to much. They enclose tablenames and the like, and are strictly optional, and I just add 'em in anyway for not much reason.
Posted: Sun Aug 14, 2005 10:16 am
by John Cartwright
Actually they are not always optional and can avoid certain problems... best to always use them.
need example
Posted: Wed Aug 24, 2005 3:39 am
by olm75
does any on have a full working example or tutorial of a search page that allows the viewer to search by 1 or any combination of fields....search must have at least 5 fields on it.....for some reason i cant do a query with more than combination of 2 fields....