Jump to content

and/or statements


123guy

Recommended Posts

this is going to be hard to explain, but I will try my best anyways.  

I am putting together a member search system with multiple fields inside of it that are optional.  

The field are First, Last, Memberid, Phone, Zipcode

 

I would like it so the user can put in as much info as they can, and my query will return all results that match the data they entered.  Also, on phone, there are three columns for it to look at matching, phone1, phone2, cell.  so If Phone matches anyone of those three, it should display it. 

 

The problem I am having is with the query.  here is what I have put together.  I think it needs something like an and/or statement...but I can't find anything for it to work :(

 

$mysqlstring = "SELECT * from customers where First='".$First."' AND Last='".$Last."' AND Phone1='".$Phone."' AND Phone2='".$Phone."' AND Cell='".$Phone."' AND MID='".$Member."' AND Zip='".$Zip."'";

 

 

Link to comment
Share on other sites

What you should do, seeing as you can have multiple phone numbers associated with a single user, is to create a table to store said phone numbers (and which member they belong to).

This is called database normalization, and is a subject which is recommend that you read up on. I generally like to recommend people to start with the following video series, as they explain the principle quite nicely:

 

PS: Moved this to the correct section.

Edited by Christian F.
Link to comment
Share on other sites

This is a common misunderstanding -- if you have a bowl of fruit, and you ask someone to hand you apples and oranges, you'll likely get 2 kinds of fruit.

 

But this isn't a Boolean AND -- it's a Boolean OR.

 

Asking for the fruit that is both an apple AND and orange will result in no matching fruit.

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.