User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 375,165 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,344 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1229 | Replies: 5
Reply
Join Date: Nov 2007
Posts: 2
Reputation: helpneeded is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
helpneeded helpneeded is offline Offline
Newbie Poster

3 condition query

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,199
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 34
Solved Threads: 824
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: 3 condition query

  #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.
'Politics' is made up of two words, 'poli,' which is Greek for 'many,' and 'tics,' which are blood-sucking insects.
- Gore Vidal
Being ignorant is not so much a shame as being unwilling to learn. - Benjamin Franklin
Reply With Quote  
Join Date: Nov 2007
Posts: 2
Reputation: helpneeded is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
helpneeded helpneeded is offline Offline
Newbie Poster

Re: 3 condition query

  #3  
Nov 21st, 2007
 </form>

<?php


$condition1 = @$_GET['cond1'] ;
$condition2 = @$_GET['cond2'] ;
$condition3 = @$_GET[#cond3'] ;

mysql_connect("dbhost","dbuser","dbpass") or die("Unable to connect to server");; 
mysql_select_db("dbname") or die("Unable to select database"); 

$query = SELECT *, from paintings where artist = condition1 and period = condition2 and  value <= condition3 ;


 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

if ($numrows == 0)
  {
  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  
Join Date: Oct 2007
Posts: 4
Reputation: judedcoutho is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
judedcoutho judedcoutho is offline Offline
Newbie Poster

Re: 3 condition query

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

Re: 3 condition query

  #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  
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation: pty is on a distinguished road 
Rep Power: 3
Solved Threads: 31
pty's Avatar
pty pty is offline Offline
Posting Pro in Training

Re: 3 condition query

  #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);
  19.  


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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 11:35 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC