Jump to content

How do I search for only filled in fields?


adamgram

Recommended Posts

So I'm very new to all this and I'm trying to build a website based on a MySQL database.  I want to make a page that has a bunch of different attributes you can search by.  The way it's set up now if you don't fill out a certain criteria it only turns up entries where that criteria is blank.  I want it to show all of the rows where the other columns match, ignoring the blank one.  Here's what I'm doing now:

 

$result = mysql_query("SELECT * FROM table

WHERE var_1='$var_1'

AND var_2='$var_2'

AND var_3='$var_3'

");

 

$var_1, $var_2, and $var_3 all come from an html form, and if certain fields aren't filled in they're left blank and respond to if... statement where $var_1==''  When I only had 4 of them I made one for each of the 16 possible combinations, but now I want to double that so it's time to figure out a better way.  I've been searching for a couple hours but it seems like I don't know enough about MySQL to know what to look for.  I just copied what I have now from a tutorial.  Anyone one to help point me in the right direction?  Thanks 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.