fat creative Posted June 5, 2008 Share Posted June 5, 2008 I am trying to do a query using the LIKE variable and I am not getting the results expected. I am either getting 0 records found or an error message. My page is at www.fatcreative.com/GFF and I am trying to search on the Land Use field. I have selected Hunting as I know there are records with Hunting in that field. The information in that field will be something like Hunting, Residential, Timber, Development. What I have happening is that if someone does not make a selection, then that selection returns an X. My code says to check the string length and if its greater than 2, then append that fields selection to the query string. I have tried several variations: if (strlen($land_use) > 2) { $query .= " AND land_use LIKE %$land_use%"; } and I've tried the same query using a lowercase like. and I've tried: if (strlen($land_use) > 2) { $query .= " AND land_use $land_use"; } These all give me an error message about not having the right syntax. I've tried: if (strlen($land_use) > 2) { $query .= " AND land_use like $land_use"; } and I've tried the same query using a lowercase like. I get an error message about unknown column called Hunting (which was my selection) I've tried: if (strlen($land_use) > 2) { $query .= " AND land_use LIKE '$land_use'"; } I get 0 records returned, which makes sense to me since no records contain JUST hunting. This seems like such a simple thing, but I am so new to this, it's quite frustrating. I'm sure it's something simple my newbieness is missing and if anyone could offer some suggestion, I would so appreciate it. Thank you so much in advance! Quote Link to comment Share on other sites More sharing options...
btherl Posted June 5, 2008 Share Posted June 5, 2008 Try this: if (strlen($land_use) > 2) { $query .= " AND land_use LIKE '%$land_use%'"; } What's missing is the quotes. Quote Link to comment Share on other sites More sharing options...
fat creative Posted June 5, 2008 Author Share Posted June 5, 2008 PERFECT! Thank you, though I am kicking myself for not figuring that out! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.