Jump to content

[SOLVED] Query using the LIKE variable


fat creative

Recommended Posts

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!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.