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
https://forums.phpfreaks.com/topic/108779-solved-query-using-the-like-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.