Jump to content

Query Result Problem


QuePID

Recommended Posts

I have a html form with 10 input fields.  The user does not have to fill in all ten input forms.  The form posts to a php which then assigns the ten $_Post values to 10 local variables that are then used to build a query string.

 

The building of the query string looks like this: ($maxsearch=1000)

 

$query = "SELECT * FROM iknew

              WHERE Private = 0 AND

              Herbarium LIKE '%$searchherbarium%' AND

              Genus LIKE '%$searchgenus%' AND

              Species LIKE '%$searchspecies%' AND

              State LIKE '%$searchstate%' AND

              County LIKE '%$searchcounty%' AND

              Family LIKE '%$searchfamily%' AND

              Locality LIKE '%$searchlocality%' AND

              Accession LIKE '%$searchaccession%' AND

              Collector LIKE '%$searchcollector%' AND

              Symbol LIKE '%$searchsymbol%'

              LIMIT $maxsearch";

 

My echo of the query string looks like this:

 

SELECT * FROM iknew WHERE Private = 0 AND Herbarium LIKE '%WVA%' AND Genus LIKE '%%' AND Species LIKE '%%' AND State LIKE '%%' AND County LIKE '%%' AND Family LIKE '%%' AND Locality LIKE '%%' AND Accession LIKE '%%' AND Collector LIKE '%%' AND Symbol LIKE '%%' LIMIT 1000

 

The above query yields 555 results (should yield 772).

 

whereas the below query yields 772 results (correct)

 

SELECT * FROM table WHERE Herbarium LIKE '%WVA%' LIMIT 1000

 

I have been wrapping the variables with %'s as I need some type of pattern match as spelling errors in the input fields is common place.

 

What is the best way to handle empty input fields with my query string while still using pattern matching?

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.