944,161 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 8771
  • MySQL RSS
Nov 21st, 2007
0

3 condition query

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
helpneeded is offline Offline
2 posts
since Nov 2007
Nov 21st, 2007
0

Re: 3 condition query

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Nov 21st, 2007
0

Re: 3 condition query

MySQL Syntax (Toggle Plain Text)
  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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
helpneeded is offline Offline
2 posts
since Nov 2007
Nov 26th, 2007
0

Re: 3 condition query

could you please tell me if i can have around 10 conditions in a singel query
Reputation Points: 10
Solved Threads: 0
Newbie Poster
judedcoutho is offline Offline
4 posts
since Oct 2007
Nov 26th, 2007
0

Re: 3 condition query

could you please tell if i can havea round 10 conditions in a single query
i want to create a multi condition search script
Reputation Points: 10
Solved Threads: 0
Newbie Poster
judedcoutho is offline Offline
4 posts
since Oct 2007
Nov 28th, 2007
0

Re: 3 condition query

php Syntax (Toggle Plain Text)
  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
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Help in Join table
Next Thread in MySQL Forum Timeline: Problem on IF STATEMENT on TRIGGER with MySql





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC