Current location: Hot Scripts Forums » Programming Languages » PHP » PHP variables matching in Mysql database


PHP variables matching in Mysql database

Reply
  #1 (permalink)  
Old 11-01-11, 04:10 PM
Aaronb Aaronb is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
PHP variables matching in Mysql database

Hi all,

Hopefully I can explain my question well enough. I have a user input form with 4 text input boxes
the data from them goes into a table with 4 columns but it needs to also search the previous records to see if any of the text input boxes data matches any of the records in the columns and return the row if 3 of them match for example if -

input text1 = column1 OR input1 = column2 OR input1 = column3 OR input1 = column4
AND
input text2 = column1 OR input2 = column2 OR input2 = column3 OR input2 = column4
AND
input text3 = column1 OR input3 = column2 OR input3 = column3 OR input3 = column4
B]AND[/B]
input text4 = column1 OR input4 = column2 OR input4 = column3 OR input4 = column4

but it doesn't need all 4 to match only say 3 of them. But the 3 could be any combination like 1st, 2nd, and 4th or it could be the 2nd, 3rd, and 4th or 1st, 3rd, and 4th etc..
Hope this makes sense and someone can help. Please and thank you in advance.
Reply With Quote
  #2 (permalink)  
Old 11-02-11, 05:58 PM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
just to make sure i got your question correctly, do you want to select a row where any 3 of the inputs match any 3 out of 4 columns in any order?
__________________
blog.phplabs.net
Reply With Quote
  #3 (permalink)  
Old 11-02-11, 06:09 PM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
perhaps this could work:

...where
column1 in (input1, input2, input3, input4) and column2 in (input1, input2, input3, input4) and column3 in (input1, input2, input3, input4)
or
column1 in (input1, input2, input3, input4) and column2 in (input1, input2, input3, input4) and column4 in (input1, input2, input3, input4)
or
column1 in (input1, input2, input3, input4) and column3 in (input1, input2, input3, input4) and column4 in (input1, input2, input3, input4)
or
column2 in (input1, input2, input3, input4) and column3 in (input1, input2, input3, input4) and column4 in (input1, input2, input3, input4);

things to consider:
* this query might return unwanted results if 2 or more column values are equal (e.g. column1 = column2, etc)
* this query might have poor execution speed
__________________
blog.phplabs.net
Reply With Quote
The Following User Says Thank You to phplabs For This Useful Post:
Aaronb (11-02-11)
  #4 (permalink)  
Old 11-02-11, 06:41 PM
Aaronb Aaronb is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
yes you have the question right and I will certainly try your idea and post the outcome and I thank you sir for the reply. Ill try it right now.
Reply With Quote
  #5 (permalink)  
Old 11-02-11, 07:22 PM
Aaronb Aaronb is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Its seems to work great!! Thank you again for your help phplabs, I do appreciate it!!
Reply With Quote
  #6 (permalink)  
Old 11-03-11, 03:47 AM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
you're welcome, i'm glad it works
__________________
blog.phplabs.net
Reply With Quote
Reply

Bookmarks

Tags
multiple variables, mysql, php, query


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie question about using PHP to get info from a MySQL Database nabnuts PHP 4 03-27-06 02:19 PM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 03:06 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 10:56 AM
Generating PHP code for MySQL ptesone General Advertisements 1 02-03-04 08:26 AM
Importing to a mysql database via php gulfan PHP 1 01-23-04 04:44 PM


All times are GMT -5. The time now is 08:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.