Jump to content

wildcard syntax


lakeshoretech

Recommended Posts

I would like some advice from someone who already has the quick answer.  User uses a form (drop down) to define a variable in their search of the db.  PHP/MYSQL

 

Choices are ALL, A, B, C.

 

EXAMPLE1

They choose B.

$variable = 'B'

 

SELECT ....

WHERE....

x table value = $variable (equals B)

 

All works perfectly.

 

EXAMPLE2

Now if they chose ALL (or don't chose), I have a problem. 

 

They choose nothing (which should be ALL records).  I need it to go back to having no WHERE portion of the sql command, or a WHERE that pulls all records.

 

They choose nothing.

$ variable = 'ALL'

 

SELECT ...

WHERE...

x table value = $variable (which now equals ALL) 

 

I thought % was a wildcard but doesn't work. 

 

This seems simple... but eludes me.    What should I use for a variable value if there is NO selection or ALL selection???? 

The WHERE x table value = has to equal SOMETHING, right?    Should I be using an IF THEN to zap the line if it equals "all"?

 

Any advice would be helpful!

 

Thanks!

 

 

 

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.