Copy link to clipboard
Copied
I want to find out what the correct syntax would be to use when querying multiple columns. What I have is:
mysql_select_db($database_LastMinuteConfirm, $LastMinuteConfirm); $province = $_POST['province']; $near_city = $_POST['near_city']; $accomm_type = $_POST['accomm_type']; $norm_price_range = $_POST['norm_price_range']; $query_Recordset1 = "SELECT * FROM lastminuteconfirm WHERE province = %$province% AND near_city = %$near_city% AND accomm_type = %$accomm_type% AND norm_price_range = %$norm_price_range%"; $Recordset1 = mysql_query($query_Recordset1, $LastMinuteConfirm) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1);
When I search it tells me: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%Gauteng% AND near_city LIKE %Pretoria (Tshwane)% AND accomm_type LIKE %boutique' at line 1".
What am I doing wrong?
Are you trying to use the SQL wildcard with the equal (=) operator? You can only use a wildcard with the Like predicate.
Copy link to clipboard
Copied
Are you trying to use the SQL wildcard with the equal (=) operator? You can only use a wildcard with the Like predicate.
Copy link to clipboard
Copied
Yeah, thanks. You set me thinking with your wildcard and I realised I only had one parameter running. Stupid of me. Will make sure next time before I waste my own or anyone elses' time again bby posting obvious questions. Anyway, thanks.
Copy link to clipboard
Copied
I don't see it as a waste of time. Sure, figuring things out on your own is usually better, but sometimes we need to ask questions, and with the help of many of the experienced users here like bregent, we not only get our questions answered but it helps others too who may be having similar issues. Even if someone isn't having the same problem - I don't know how many times I've come across tidbits like this, maybe even bookmarked the page and it came in handy later on.
Copy link to clipboard
Copied
Thanks Lon