3 condition query

Reply

Join Date: Nov 2007
Posts: 2
Reputation: helpneeded is an unknown quantity at this point 
Solved Threads: 0
helpneeded helpneeded is offline Offline
Newbie Poster

3 condition query

 
0
  #1
Nov 21st, 2007
Hi, Im only used to basic sql queries. wonder if anyone can help with the below - or at least get me pointing in the direction of the correct resource to solve.

I have a table, with fields a,b,c,d,e,f

I need to run a query that shows from the above table all matches to 3 conditions in this order..

display if a = condition1 and b = condition2 and e is less than or equal to the value in e

my problem is whilst Im able to write these queries seperate, Im struggling to write the query as one without getting errors.

Can anyone help - either suggest how the query should look, or point me to some resource.. many thanks.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: 3 condition query

 
0
  #2
Nov 21st, 2007
what have you tried? The logical query would be
where a = condition1 and b = condition2 and e <= something
but since we don't know what condition1 and condition2 are we can't give much more help. So post your actual code if you want better help.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: helpneeded is an unknown quantity at this point 
Solved Threads: 0
helpneeded helpneeded is offline Offline
Newbie Poster

Re: 3 condition query

 
0
  #3
Nov 21st, 2007
  1. </form>
  2.  
  3. <?php
  4.  
  5.  
  6. $condition1 = @$_GET['cond1'] ;
  7. $condition2 = @$_GET['cond2'] ;
  8. $condition3 = @$_GET[#cond3'] ;
  9.  
  10. mysql_connect("dbhost","dbuser","dbpass") OR die("Unable to connect to server");;
  11. mysql_select_db("dbname") OR die("Unable to select database");
  12.  
  13. $query = SELECT *, FROM paintings WHERE artist = condition1 AND period = condition2 AND value <= condition3 ;
  14.  
  15.  
  16. $numresults=mysql_query($query);
  17. $numrows=mysql_num_rows($numresults);
  18.  
  19. if ($numrows == 0)
  20. {
  21. echo "<p>Sorry, nothing found that matches your request etc</p>";

Hi, thanks for that - I think Ive posted this correct

Ive added what you suggested how I think it should be written.. it seems awfully short yet sensible - can you confirm you think I have written it correctly.. after the huge number of errors my last attempt got, I thought Id check Im understanding you prior to trying it again.

Thanks again. Especially for the quick response..
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 4
Reputation: judedcoutho is an unknown quantity at this point 
Solved Threads: 0
judedcoutho judedcoutho is offline Offline
Newbie Poster

Re: 3 condition query

 
0
  #4
Nov 26th, 2007
could you please tell me if i can have around 10 conditions in a singel query
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 4
Reputation: judedcoutho is an unknown quantity at this point 
Solved Threads: 0
judedcoutho judedcoutho is offline Offline
Newbie Poster

Re: 3 condition query

 
0
  #5
Nov 26th, 2007
could you please tell if i can havea round 10 conditions in a single query
i want to create a multi condition search script
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 521
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: 3 condition query

 
0
  #6
Nov 28th, 2007
  1. $condition1 = @$_GET['cond1'] ;
  2. $condition2 = @$_GET['cond2'] ;
  3. $condition3 = @$_GET['cond3'] ;
  4.  
  5. mysql_connect("dbhost","dbuser","dbpass") or die("Unable to connect to server");
  6. mysql_select_db("dbname") or die("Unable to select database");
  7.  
  8. $query = sprintf(" select *
  9. from paintings
  10. where artist = '%s'
  11. and period = '%s'
  12. and value <= '%s' "
  13. , mysql_real_escape_string($condition1)
  14. , mysql_real_escape_string($condition2)
  15. , mysql_real_escape_string($condition3)
  16. );
  17.  
  18. $result = mysql_query($query);


Should look somehting more like that. Not used php for ages so it may not be work but I think you need a book and learn the basics of SQL and PHP before putting them together
Note to self... pocket cup
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC