Ask a Question related to PHP Development, Design and Development.
-
Bonge Boo! #1
MYSQL query: AND OR?
This will probably sound stupid.
How would you do a MYSQL query that was to evaluate if either condition A or
B was meet? And if so, in what order would the result come out?
Say I have
select * from images where model_ID ={$_REQUEST['model_ID']} , image_ID =
{$_REQUEST['image_ID']}
I know I could do an XOR, which is "if either, but not both" but I don't
know what "if either, use A first" would be.
Bonge Boo! Guest
-
Is this a MySQL Query bug?
I wrote a SQL script in MySQL Query, and saved it as script.sql, but when I executed it in windows command line "mysql -h localhost -u root... -
MySQL Query Cache Not Working: MySQL 5 / Windows XP
Please excuse this post if you've already read it on mailing.database.mysql - i just discovered these other groups. future posts will be... -
MySql query help
Hey, I am trying to retrive information from a database using the 'Mysql_fetch_assoc' function, but the problem is.. it is just one row of data... -
Query log for mySQL?
Is there a simple way to create a query log for mySQL? I've been asked^h^h^h^h^h told to add a layer of auditing on an existing application. It's... -
mysql/php query
I have a question about (i think) joining. If I have a table in a database that has this info: key - name - favorite 1 - john - 2 2 - ... -
Chris Hope #2
Re: MYSQL query: AND OR?
Bonge Boo! wrote:
Do you mean this is what you want?> This will probably sound stupid.
>
> How would you do a MYSQL query that was to evaluate if either condition A
> or B was meet? And if so, in what order would the result come out?
>
> Say I have
>
> select * from images where model_ID ={$_REQUEST['model_ID']} , image_ID =
> {$_REQUEST['image_ID']}
>
> I know I could do an XOR, which is "if either, but not both" but I don't
> know what "if either, use A first" would be.
select * from images where model_ID = 'foo' or image_ID = 'bar'
Unless you specifically set the order using "order by" the order is
essentially random eg you could order it "order by model_ID, image_ID"
--
Chris Hope - The Electric Toolbox - [url]http://www.electrictoolbox.com/[/url]
Chris Hope Guest
-
Bonge Boo! #3
Re: MYSQL query: AND OR?
On 7/7/04 9:57 pm, in article 1089233879_15263@216.128.74.129, "Chris Hope"
<blackhole@electrictoolbox.com> wrote:
Not really. I was hoping for:>>> Say I have
>>
>> select * from images where model_ID ={$_REQUEST['model_ID']} , image_ID =
>> {$_REQUEST['image_ID']}
>>
>> I know I could do an XOR, which is "if either, but not both" but I don't
>> know what "if either, use A first" would be.
> Do you mean this is what you want?
>
> select * from images where model_ID = 'foo' or image_ID = 'bar'
>
> Unless you specifically set the order using "order by" the order is
> essentially random eg you could order it "order by model_ID, image_ID"
If A is true OR b is true do something, but if b is true, then ignore the a
part and just return b query
I'm not explaining very well. The problem I had is that when my query is
looking for 2 variables to be passed, if one of them isn't there, then the
query fails with an error message.
I was trying to have a page which says "if no value for image_ID" is set,
then simply use the model_ID to get a result out, which will display an
image.
However if an explicit image_ID is set, then return this image.
Maybe I'm doing this wrongly and should be using
if (isset($image_ID) {
Do this mysql query
}else {
Do another mysql query
}
Problem is I'm using Golive and its never that keen on you messing with the
"content sources" Dreamweaver also behaves similarly AFAIK.
Bonge Boo! Guest
-
Alvaro G Vicario #4
Re: MYSQL query: AND OR?
*** Bonge Boo! wrote/escribió (Thu, 08 Jul 2004 09:04:44 +0100):
You really want two separates queries, don't you?> If A is true OR b is true do something, but if b is true, then ignore the a
> part and just return b query
select this from table where a or b
select that from table where not b
Then use PHP to compose a custom query string.> I'm not explaining very well. The problem I had is that when my query is
> looking for 2 variables to be passed, if one of them isn't there, then the
> query fails with an error message.
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Alvaro G Vicario Guest
-
bill #5
Re: MYSQL query: AND OR?
On Wed, 07 Jul 2004 20:50:20 +0100, Bonge Boo! <bingbong@spamcop.net>
wrote:
A ternary operator might be what you're looking for:>How would you do a MYSQL query that was to evaluate if either condition A or
>B was meet? And if so, in what order would the result come out?
($a = true) ? ($do = "a and b") : ($do = "");
[url]http://us2.php.net/language.operators[/url]
bill Guest
-
George Hernandez #6
Re: MYSQL query: AND OR?
SELECT * FROM your_table_name WHERE condition_1 AND condition_2
"bill" <whoami@whereami.not> wrote in message
news:ikhte0hqdrfrsmino3hh8erhpihjqu3sgt@4ax.com...
: On Wed, 07 Jul 2004 20:50:20 +0100, Bonge Boo! <bingbong@spamcop.net>
: wrote:
:
: >How would you do a MYSQL query that was to evaluate if either condition A
or
: >B was meet? And if so, in what order would the result come out?
:
: A ternary operator might be what you're looking for:
:
: ($a = true) ? ($do = "a and b") : ($do = "");
:
: [url]http://us2.php.net/language.operators[/url]
:
:
George Hernandez Guest



Reply With Quote

