| | |
3 condition query
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
what have you tried? The logical query would be
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.
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.
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
MySQL Syntax (Toggle Plain Text)
</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..
php Syntax (Toggle Plain Text)
$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 = sprintf(" select * from paintings where artist = '%s' and period = '%s' and value <= '%s' " , mysql_real_escape_string($condition1) , mysql_real_escape_string($condition2) , mysql_real_escape_string($condition3) ); $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
![]() |
Similar Threads
- Code for Deleting a Record in a database?? (Visual Basic 4 / 5 / 6)
- how to bind two item in datagrid, so that i can get details of 2 in details (ASP.NET)
- Trying to use LIKE statement on JOIN query (MySQL)
- how to access dropdown list entries in python psp site (Python)
- if statement didnt work as expected (C)
- how to select null values in condition (MySQL)
- Waiting Room Access DB (Visual Basic 4 / 5 / 6)
- probelm with autogenerated mysql query (PHP)
- problem with autogenerated mysql query (MySQL)
- Querying within the results of a previous query? (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: Help in Join table
- Next Thread: Problem on IF STATEMENT on TRIGGER with MySql
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api aws bizspark breathalyzer changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






