logic operands problem

logic operands problem

am 07.12.2009 11:52:42 von Merlin Morgenstern

Hello everybody,

I am having trouble finding a logic for following problem:

Should be true if:
page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3

The result should never contain 1 AND 2 in the same time.

This obviously does not work:
(page = 1 OR page = 3) OR (page = 2 OR page = 3)

This also does not work:
(page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1)

Has somebody an idea how to solve this?

Thank you in advance for any help!

Merlin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: logic operands problem

am 07.12.2009 11:56:58 von Devendra Jadhav

--001636920c13123d57047a215143
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

what do you think about this?
if( ! (page == 1 && page == 2)){
//here
}

On Mon, Dec 7, 2009 at 4:22 PM, Merlin Morgenstern wr=
ote:

> Hello everybody,
>
> I am having trouble finding a logic for following problem:
>
> Should be true if:
> page =3D 1 OR page =3D 3, but it should also be true if page =3D 2 OR pag=
e =3D 3
>
> The result should never contain 1 AND 2 in the same time.
>
> This obviously does not work:
> (page =3D 1 OR page =3D 3) OR (page =3D 2 OR page =3D 3)
>
> This also does not work:
> (page =3D 1 OR page =3D 3 AND page !=3D 2) OR (page =3D 2 OR page =3D 3 A=
ND page !=3D
> 1)
>
> Has somebody an idea how to solve this?
>
> Thank you in advance for any help!
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--=20
Devendra Jadhav
देवेंदॠà¤° =
जाधव

--001636920c13123d57047a215143--

Re: logic operands problem

am 07.12.2009 12:08:26 von Merlin Morgenstern

--------------040701000006030305070801
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit



Devendra Jadhav wrote:
> what do you think about this?
> if( ! (page == 1 && page == 2)){
> //here
> }
>

Well a simple && (and) does not help.

I want to have all results that contain either page = 1 OR page = 3, AND
in the same time I want to have the results that contain page=2 OR page= 3
, But the result should never contain page = 1 and page = 2 in the same
time.

Any further idea?





> On Mon, Dec 7, 2009 at 4:22 PM, Merlin Morgenstern
> > wrote:
>
> Hello everybody,
>
> I am having trouble finding a logic for following problem:
>
> Should be true if:
> page = 1 OR page = 3, but it should also be true if page = 2 OR
> page = 3
>
> The result should never contain 1 AND 2 in the same time.
>
> This obviously does not work:
> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>
> This also does not work:
> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND
> page != 1)
>
> Has somebody an idea how to solve this?
>
> Thank you in advance for any help!
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
> --
> Devendra Jadhav
> देवेंद्र जाधव

--------------040701000006030305070801--

Re: logic operands problem

am 07.12.2009 12:12:23 von Thales Jacobi

I think you could use another braket on the second example:

((page== 1 OR page== 3) AND page!= 2) OR ((page== 2 OR page== 3) AND page !=
1)

Other than that I don't think I can help.

How come the page can be 1 or 3, but not 2?
I think you could change the logic, but I don't have enough info about your
code. If page is 1 or 3, it won't be 2 (obviously), but why 2 or 3 is
acceptable?



"Merlin Morgenstern" wrote in message
news:8E.77.13248.A9EDC1B4@pb1.pair.com...
> Hello everybody,
>
> I am having trouble finding a logic for following problem:
>
> Should be true if:
> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>
> The result should never contain 1 AND 2 in the same time.
>
> This obviously does not work:
> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>
> This also does not work:
> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page !=
> 1)
>
> Has somebody an idea how to solve this?
>
> Thank you in advance for any help!
>
> Merlin


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: logic operands problem

am 07.12.2009 12:18:05 von Ashley Sheridan

--=-zCJAakhFiWZF0QGyB1vx
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote:

> Hello everybody,
>
> I am having trouble finding a logic for following problem:
>
> Should be true if:
> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>
> The result should never contain 1 AND 2 in the same time.
>
> This obviously does not work:
> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>
> This also does not work:
> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1)
>
> Has somebody an idea how to solve this?
>
> Thank you in advance for any help!
>
> Merlin
>


I thought this might work:

(page = 3) OR (page = 1 XOR 2)

But having given it more thought, I'm not so sure. I assume from your
example that this is MySQL code and not PHP. Having said that, how can a
field of one row have more than one value? Surely `page` is either 1, 2
or 3, not two of them at once. How do you want your results pulled?
Assuming you have rows containing all three values, how do you decide
which of the pair of results you want?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-zCJAakhFiWZF0QGyB1vx--

Re: logic operands problem

am 07.12.2009 12:19:38 von Peter Ford

Merlin Morgenstern wrote:
> Hello everybody,
>
> I am having trouble finding a logic for following problem:
>
> Should be true if:
> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>
> The result should never contain 1 AND 2 in the same time.
>
> This obviously does not work:
> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>
> This also does not work:
> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
> != 1)
>
> Has somebody an idea how to solve this?
>
> Thank you in advance for any help!
>
> Merlin


Surely what you need is xor (exclusive-or)
I can't believe a programmer has never heard of that!

(page==1 XOR page==2) AND page==3

--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: logic operands problem

am 07.12.2009 12:37:27 von Merlin Morgenstern

Peter Ford wrote:
> Merlin Morgenstern wrote:
>> Hello everybody,
>>
>> I am having trouble finding a logic for following problem:
>>
>> Should be true if:
>> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>>
>> The result should never contain 1 AND 2 in the same time.
>>
>> This obviously does not work:
>> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>>
>> This also does not work:
>> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
>> != 1)
>>
>> Has somebody an idea how to solve this?
>>
>> Thank you in advance for any help!
>>
>> Merlin
>
>
> Surely what you need is xor (exclusive-or)
> I can't believe a programmer has never heard of that!
>
> (page==1 XOR page==2) AND page==3
>

HEllo Peter,

thank you for your reply. I know about XOR, but unfortunatelly I might
not know how to use it properly OR it is not aplicable on SQL. I am
trying to retrive data:
SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3)

I know this is not php, but I thought the logic should be the same in
this case?!

Regards, Merlin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: logic operands problem

am 07.12.2009 12:39:30 von Ashley Sheridan

--=-uQD5pGfShd4Dw+5nDEii
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote:

> Peter Ford wrote:
> > Merlin Morgenstern wrote:
> >> Hello everybody,
> >>
> >> I am having trouble finding a logic for following problem:
> >>
> >> Should be true if:
> >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
> >>
> >> The result should never contain 1 AND 2 in the same time.
> >>
> >> This obviously does not work:
> >> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
> >>
> >> This also does not work:
> >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
> >> != 1)
> >>
> >> Has somebody an idea how to solve this?
> >>
> >> Thank you in advance for any help!
> >>
> >> Merlin
> >
> >
> > Surely what you need is xor (exclusive-or)
> > I can't believe a programmer has never heard of that!
> >
> > (page==1 XOR page==2) AND page==3
> >
>
> HEllo Peter,
>
> thank you for your reply. I know about XOR, but unfortunatelly I might
> not know how to use it properly OR it is not aplicable on SQL. I am
> trying to retrive data:
> SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3)
>
> I know this is not php, but I thought the logic should be the same in
> this case?!
>
> Regards, Merlin
>


This will likely retrieve all the records in the table. Is that what
your tests have shown?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-uQD5pGfShd4Dw+5nDEii--

Re: Re: logic operands problem

am 07.12.2009 12:48:59 von sandortamas

I don't really get it. This is a select statement working with the datas of
one table.
A field of a record (namely "page" here) can only take one value, so it is
totally nonsense to give XOR for that field.

I think you want to select two different recordsets: one with page 1 and 3,
and another with 2 and 3, am I right?

SanTa

----- Original Message -----
From: "Ashley Sheridan"
To: "Merlin Morgenstern"
Cc: "Peter Ford" ;
Sent: Monday, December 07, 2009 12:39 PM
Subject: Re: [PHP] Re: logic operands problem


> On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote:
>
>> Peter Ford wrote:
>> > Merlin Morgenstern wrote:
>> >> Hello everybody,
>> >>
>> >> I am having trouble finding a logic for following problem:
>> >>
>> >> Should be true if:
>> >> page = 1 OR page = 3, but it should also be true if page = 2 OR page =
>> >> 3
>> >>
>> >> The result should never contain 1 AND 2 in the same time.
>> >>
>> >> This obviously does not work:
>> >> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>> >>
>> >> This also does not work:
>> >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
>> >> != 1)
>> >>
>> >> Has somebody an idea how to solve this?
>> >>
>> >> Thank you in advance for any help!
>> >>
>> >> Merlin
>> >
>> >
>> > Surely what you need is xor (exclusive-or)
>> > I can't believe a programmer has never heard of that!
>> >
>> > (page==1 XOR page==2) AND page==3
>> >
>>
>> HEllo Peter,
>>
>> thank you for your reply. I know about XOR, but unfortunatelly I might
>> not know how to use it properly OR it is not aplicable on SQL. I am
>> trying to retrive data:
>> SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3)
>>
>> I know this is not php, but I thought the logic should be the same in
>> this case?!
>>
>> Regards, Merlin
>>
>
>
> This will likely retrieve all the records in the table. Is that what
> your tests have shown?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: logic operands problem

am 07.12.2009 12:49:17 von Merlin Morgenstern

--------------050203070800090301000309
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit



Ashley Sheridan wrote:
> On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote:
>> Hello everybody,
>>
>> I am having trouble finding a logic for following problem:
>>
>> Should be true if:
>> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>>
>> The result should never contain 1 AND 2 in the same time.
>>
>> This obviously does not work:
>> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>>
>> This also does not work:
>> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1)
>>
>> Has somebody an idea how to solve this?
>>
>> Thank you in advance for any help!
>>
>> Merlin
>>
>>
>
> I thought this might work:
>
> (page = 3) OR (page = 1 XOR 2)
>
> But having given it more thought, I'm not so sure. I assume from your
> example that this is MySQL code and not PHP. Having said that, how can
> a field of one row have more than one value? Surely `page` is either
> 1, 2 or 3, not two of them at once. How do you want your results
> pulled? Assuming you have rows containing all three values, how do you
> decide which of the pair of results you want?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>


You have described the problem very well. This is exactly where I can
not find a solution.

the page number translates to the following: 1= first page 2= following
pages 3= all pages

This are the options a user has while booking a product on my site. Now
if ther is a new
client that wants to book all pages, I need to query the table to find
out if the spot is available.
The spot would be full if page 1 has more results then 3 , OR all
following pages have more then 3 results. So to find out if "all pages"
option would be available I need to query the db to retrieve all
results, that are (page = 3) OR (page = 1 XOR 2)

Am I wrong?


--------------050203070800090301000309--

Re: Re: logic operands problem

am 07.12.2009 12:50:24 von Merlin Morgenstern

--------------090702060205030705050304
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit



Ashley Sheridan wrote:
> On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote:
>> Peter Ford wrote:
>> > Merlin Morgenstern wrote:
>> >> Hello everybody,
>> >>
>> >> I am having trouble finding a logic for following problem:
>> >>
>> >> Should be true if:
>> >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>> >>
>> >> The result should never contain 1 AND 2 in the same time.
>> >>
>> >> This obviously does not work:
>> >> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>> >>
>> >> This also does not work:
>> >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
>> >> != 1)
>> >>
>> >> Has somebody an idea how to solve this?
>> >>
>> >> Thank you in advance for any help!
>> >>
>> >> Merlin
>> >
>> >
>> > Surely what you need is xor (exclusive-or)
>> > I can't believe a programmer has never heard of that!
>> >
>> > (page==1 XOR page==2) AND page==3
>> >
>>
>> HEllo Peter,
>>
>> thank you for your reply. I know about XOR, but unfortunatelly I might
>> not know how to use it properly OR it is not aplicable on SQL. I am
>> trying to retrive data:
>> SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3)
>>
>> I know this is not php, but I thought the logic should be the same in
>> this case?!
>>
>> Regards, Merlin
>>
>>
>
> This will likely retrieve all the records in the table. Is that what
> your tests have shown?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>

Exactly! This is unfortunatelly what happens! Any ideas how to get the
correct results?

--------------090702060205030705050304--

Re: logic operands problem

am 07.12.2009 12:51:45 von Ashley Sheridan

--=-CaY1uHmT13fDT1qm9hRN
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2009-12-07 at 12:49 +0100, Merlin Morgenstern wrote:

>
> Ashley Sheridan wrote:
> > On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote:
> >> Hello everybody,
> >>
> >> I am having trouble finding a logic for following problem:
> >>
> >> Should be true if:
> >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
> >>
> >> The result should never contain 1 AND 2 in the same time.
> >>
> >> This obviously does not work:
> >> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
> >>
> >> This also does not work:
> >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1)
> >>
> >> Has somebody an idea how to solve this?
> >>
> >> Thank you in advance for any help!
> >>
> >> Merlin
> >>
> >>
> >
> > I thought this might work:
> >
> > (page = 3) OR (page = 1 XOR 2)
> >
> > But having given it more thought, I'm not so sure. I assume from your
> > example that this is MySQL code and not PHP. Having said that, how can
> > a field of one row have more than one value? Surely `page` is either
> > 1, 2 or 3, not two of them at once. How do you want your results
> > pulled? Assuming you have rows containing all three values, how do you
> > decide which of the pair of results you want?
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
>
>
> You have described the problem very well. This is exactly where I can
> not find a solution.
>
> the page number translates to the following: 1= first page 2= following
> pages 3= all pages
>
> This are the options a user has while booking a product on my site. Now
> if ther is a new
> client that wants to book all pages, I need to query the table to find
> out if the spot is available.
> The spot would be full if page 1 has more results then 3 , OR all
> following pages have more then 3 results. So to find out if "all pages"
> option would be available I need to query the db to retrieve all
> results, that are (page = 3) OR (page = 1 XOR 2)
>
> Am I wrong?
>


I'm pretty confused by your logic, but I think the only way you can
achieve what you want is with multiple queries and counts.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-CaY1uHmT13fDT1qm9hRN--

Re: Re: logic operands problem

am 07.12.2009 12:51:46 von Merlin Morgenstern

--------------090903090408020001030704
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 8bit



Sándor Tamás (HostWare Kft.) wrote:
> I don't really get it. This is a select statement working with the
> datas of one table.
> A field of a record (namely "page" here) can only take one value, so
> it is totally nonsense to give XOR for that field.
>
> I think you want to select two different recordsets: one with page 1
> and 3, and another with 2 and 3, am I right?
>
> SanTa
>
Yes, you are right. Any ideas on how to do this within one query?



> ----- Original Message ----- From: "Ashley Sheridan"
>
> To: "Merlin Morgenstern"
> Cc: "Peter Ford" ;
> Sent: Monday, December 07, 2009 12:39 PM
> Subject: Re: [PHP] Re: logic operands problem
>
>
>> On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote:
>>
>>> Peter Ford wrote:
>>> > Merlin Morgenstern wrote:
>>> >> Hello everybody,
>>> >>
>>> >> I am having trouble finding a logic for following problem:
>>> >>
>>> >> Should be true if:
>>> >> page = 1 OR page = 3, but it should also be true if page = 2 OR
>>> page = >> 3
>>> >>
>>> >> The result should never contain 1 AND 2 in the same time.
>>> >>
>>> >> This obviously does not work:
>>> >> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>>> >>
>>> >> This also does not work:
>>> >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND
>>> page
>>> >> != 1)
>>> >>
>>> >> Has somebody an idea how to solve this?
>>> >>
>>> >> Thank you in advance for any help!
>>> >>
>>> >> Merlin
>>> >
>>> >
>>> > Surely what you need is xor (exclusive-or)
>>> > I can't believe a programmer has never heard of that!
>>> >
>>> > (page==1 XOR page==2) AND page==3
>>> >
>>>
>>> HEllo Peter,
>>>
>>> thank you for your reply. I know about XOR, but unfortunatelly I might
>>> not know how to use it properly OR it is not aplicable on SQL. I am
>>> trying to retrive data:
>>> SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3)
>>>
>>> I know this is not php, but I thought the logic should be the same in
>>> this case?!
>>>
>>> Regards, Merlin
>>>
>>
>>
>> This will likely retrieve all the records in the table. Is that what
>> your tests have shown?
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>

--------------090903090408020001030704--

Re: logic operands problem

am 07.12.2009 13:22:43 von Lester Caine

Merlin Morgenstern wrote:
> You have described the problem very well. This is exactly where I can
> not find a solution.
>
> the page number translates to the following: 1= first page 2= following
> pages 3= all pages
>
> This are the options a user has while booking a product on my site. Now
> if ther is a new
> client that wants to book all pages, I need to query the table to find
> out if the spot is available.
> The spot would be full if page 1 has more results then 3 , OR all
> following pages have more then 3 results. So to find out if "all pages"
> option would be available I need to query the db to retrieve all
> results, that are (page = 3) OR (page = 1 XOR 2)
>
> Am I wrong?

Yes I think you are! And XOR may be wrong here. XOR is a binary operator, so
think of the number as 0b0011 for 3 0b0010 for 2 and 0b0001 for 1 ...
1 XOR 2 will give a result of 0b0011 - so = 3

What you are trying to do just seems wrong in general.
'if page 1 has more results then 3' requires you count the number of page 1
records and compare with the number of page 3 records. And the same with page 2
results.

I don't think you are giving enough detail to know exactly what you are trying
to achieve, but what you are describing so far does not make sense 'logically'.
If you are trying to book a 'set' of pages but can't if one of that set is
already booked, then I don't think you can do this with a single query. You need
to check each 'page' individually. If this was room booking, then one would have
to check there are no other bookings for a day in the period for that particular
room. Or putting it another way, there are no days in the period when all rooms
are booked, but in this case you still need to know that a particular room is
available for the whole period.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re: logic operands problem

am 07.12.2009 13:26:13 von Ashley Sheridan

--=-x6HuUyg4vs0SdZTotD/I
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2009-12-07 at 12:26 +0000, Ford, Mike wrote:

> This is pretty much why SQL does not offer you the XOR operator!


Someone better tell the MySQL developers then...

http://dev.mysql.com/doc/refman/5.0/en/logical-operators.htm l


Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-x6HuUyg4vs0SdZTotD/I--

RE: Re: logic operands problem

am 07.12.2009 13:26:50 von M.Ford

> -----Original Message-----
> From: Merlin Morgenstern [mailto:merlin_x@fastmail.fm]
> Sent: 07 December 2009 11:52
> To: "S=E1ndor Tam=E1s (HostWare Kft.)"
> Cc: Merlin Morgenstern; php-general@lists.php.net
> Subject: Re: [PHP] Re: logic operands problem
>=20
>=20
>=20
> S=E1ndor Tam=E1s (HostWare Kft.) wrote:
> > I don't really get it. This is a select statement working with the
> > datas of one table.
> > A field of a record (namely "page" here) can only take one value,
> so
> > it is totally nonsense to give XOR for that field.
> >
> > I think you want to select two different recordsets: one with page
> 1
> > and 3, and another with 2 and 3, am I right?
> >
> > SanTa
> >
> Yes, you are right. Any ideas on how to do this within one query?

If you need these two specific recordsets, I don't see how you can. You'll=
have to make two queries and do any further logic in PHP using the two set=
s of results.

XOR is a total nonsense in this situation -- as your condition is targeting=
a single, single-valued field, the value you are testing cannot possibly b=
e simultaneously both 1 and 2, so the XOR operator is essentially redundant=
and effectively the same as the OR operator. This is pretty much why SQL d=
oes not offer you the XOR operator! All of the condition variants I've seen=
in this thread so far pretty much boil down to (page=3D1 OR page=3D2 OR pa=
ge=3D3), which, as you found, returns your entire database.

Cheers!

Mike
--=20
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,=20
Woodhouse Lane, LEEDS,=A0 LS1 3HE,=A0 United Kingdom=20
Email: m.ford@leedsmet.ac.uk=20
Tel: +44 113 812 4730




To view the terms under which this email is distributed, please go to http:=
//disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re: logic operands problem

am 07.12.2009 13:56:30 von M.Ford

------_=_NextPart_001_01CA773C.B32C622B
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: base64
Content-length: 1839

VW0sIHllcywgcHJvYmFibHkgbmVlZCB0byB1cGRhdGUgbXkgT3JhY2xlIHJl
ZmVyZW5jZSBtYW51YWxzIOKAkyBJIHRoaW5rIHRoZSBiaWcgZmF0IHBhcGVy
IG9uZSBvbiBteSBzaGVsZiBtYXkgZXZlbiByZWZlciB0byBBTlNJIFNRTDg5
LCB3aGljaCBJIHN1c3BlY3QgaXMgcHJldHR5IG11Y2ggd2hhdCBteSBoZWFk
IGNvbnRlbnQgaXMgYmFzZWQgb24gYWxzby4gSW4gYW55IGNhc2UsIFhPUiBk
b2VzbuKAmXQgYXBwZWFyIHRvIGJlIGluIHRoZSBsYXRlc3QgQU5TSS9JU08g
U1FMIHN0YW5kYXJkcyBJIGhhdmUgYWNjZXNzIHRvIChBTlNJIDIwMDMpLCBz
byB0aGlzIG1heSBiZSBhIE15U1FMLXNwZWNpZmljIGV4dGVuc2lvbi4NCg0K
IA0KDQpCdXQgaG93ZXZlciB5b3Ugc2xpY2UgaXQsIFhPUiBpcyB0aGUgd3Jv
bmcgc29sdXRpb24gZm9yIHRoZSBwcm9ibGVtIGF0IGhhbmQhIDspDQoNCg0K
Q2hlZXJzIQ0KDQpNaWtlDQoNCiAtLSANCk1pa2UgRm9yZCwNCkVsZWN0cm9u
aWMgSW5mb3JtYXRpb24gRGV2ZWxvcGVyLCBMaWJyYXJpZXMgYW5kIExlYXJu
aW5nIElubm92YXRpb24sICANCkxlZWRzIE1ldHJvcG9saXRhbiBVbml2ZXJz
aXR5LCBDNTA3LCBDaXZpYyBRdWFydGVyIENhbXB1cywgDQpXb29kaG91c2Ug
TGFuZSwgTEVFRFMsICBMUzEgM0hFLCAgVW5pdGVkIEtpbmdkb20gDQpFbWFp
bDogbS5mb3JkQGxlZWRzbWV0LmFjLnVrIA0KVGVsOiArNDQgMTEzIDgxMiA0
NzMwDQoNCiANCg0KIA0KDQogDQoNCkZyb206IEFzaGxleSBTaGVyaWRhbiBb
bWFpbHRvOmFzaEBhc2hsZXlzaGVyaWRhbi5jby51a10gDQpTZW50OiAwNyBE
ZWNlbWJlciAyMDA5IDEyOjI2DQpUbzogRm9yZCwgTWlrZQ0KQ2M6IHBocC1n
ZW5lcmFsQGxpc3RzLnBocC5uZXQNClN1YmplY3Q6IFJFOiBbUEhQXSBSZTog
bG9naWMgb3BlcmFuZHMgcHJvYmxlbQ0KDQogDQoNCk9uIE1vbiwgMjAwOS0x
Mi0wNyBhdCAxMjoyNiArMDAwMCwgRm9yZCwgTWlrZSB3cm90ZToNCg0KDQoN
ClRoaXMgaXMgcHJldHR5IG11Y2ggd2h5IFNRTCBkb2VzIG5vdCBvZmZlciB5
b3UgdGhlIFhPUiBvcGVyYXRvciENCg0KDQpTb21lb25lIGJldHRlciB0ZWxs
IHRoZSBNeVNRTCBkZXZlbG9wZXJzIHRoZW4uLi4NCg0KaHR0cDovL2Rldi5t
eXNxbC5jb20vZG9jL3JlZm1hbi81LjAvZW4vbG9naWNhbC1vcGVyYXRvcnMu
aHRtbA0KDQoNCg0KVGhhbmtzLA0KQXNoDQpodHRwOi8vd3d3LmFzaGxleXNo
ZXJpZGFuLmNvLnVrDQoNCg0KDQogDQoNCgoKVG8gdmlldyB0aGUgdGVybXMg
dW5kZXIgd2hpY2ggdGhpcyBlbWFpbCBpcyBkaXN0cmlidXRlZCwgcGxlYXNl
IGdvIHRvIGh0dHA6Ly9kaXNjbGFpbWVyLmxlZWRzbWV0LmFjLnVrL2VtYWls
Lmh0bQo=

------_=_NextPart_001_01CA773C.B32C622B--

Re: logic operands problem

am 07.12.2009 15:41:03 von Kim Madsen

Hey Merlin

Merlin Morgenstern wrote on 2009-12-07 11:52:
> Hello everybody,
>
> I am having trouble finding a logic for following problem:
>
> Should be true if:
> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>
> The result should never contain 1 AND 2 in the same time.
>
> This obviously does not work:
> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>
> This also does not work:
> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
> != 1)
>
> Has somebody an idea how to solve this?

I've read the entire thread and can see that this is a MySQL query you
want to make (I was about to tell you about the == comparison and the $
in a variable in PHP).

What you want is all results containing 1,2 or 3, so make a "WHERE page
IN(1,2,3)" and use PHP logic to figure out if a free slot is available
or not. Or rewrite your booking routine (use data and time fields
instead, maybe by creating a bunch of free slots and then a booked field
with a default of "0", changed to "1" when booked)

--
Kind regards
Kim Emax - masterminds.dk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: logic operands problem

am 07.12.2009 15:53:01 von TedD

At 11:52 AM +0100 12/7/09, Merlin Morgenstern wrote:
>Hello everybody,
>
>I am having trouble finding a logic for following problem:
>
>Should be true if:
>page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>
>The result should never contain 1 AND 2 in the same time.
>
>This obviously does not work:
>(page = 1 OR page = 3) OR (page = 2 OR page = 3)
>
>This also does not work:
>(page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1)
>
>Has somebody an idea how to solve this?
>
>Thank you in advance for any help!
>
>Merlin

Merlin:

The variable "page" cannot hold two values at the same time and thus
your statement "The result should never contain 1 AND 2 in the same
time" is nonsense.

Now if you are working two variables, namely $a and $b and you want
an algorithm to solve your problem, it's simple.

if ($a + $b > 3)
{
$result = true;
}
else
{
$result = false;
}

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: logic operands problem

am 07.12.2009 16:05:20 von Merlin Morgenstern

--------------010002000300060607070807
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi everybody,

thank you for all the help and thoughts. I have solved it, but I guess
it is not an elegant solution. What I do now, is simply check again for
the second case. There are 2 cases. Either first page OR all pages,
second case: following pages OR all pages.

My booking checking looks now as following:



############################################################ ####################################
# on which page will the tl be placed?
if ($data[page] == 3){ // all pages
$where_page = 'AND (page = 1 OR page = 3)'; // unfortunatelly we
have to test later on page = 2 OR page = 3. No solution inside one
query. We tried also (page=1 XOR page=2) OR page = 3
$where_page_2 = 'AND (page = 2 OR page = 3)';
}
else{ // page one or all following pages
$where_page = 'AND page = '.$data[page];
}

############################################################ ####################################

############################################################ ####################################
# find out first possible booking period
do{
// get all toplistings that are at least with one day inside the
desired booking period
$stmt= "
SELECT
*
FROM
$DB.$T54
WHERE
cat_id = '$data[cat_id]'
AND cat_type = '$data[cat_type]'
$where_page
AND
(
(start_date <= '$new_start' AND expires >=
'$new_start')
OR (start_date <= '$new_end' AND expires >= '$new_end')
OR (start_date >= '$new_start' AND start_date<=
'$new_end')
)
";
#echo $stmt.$br;
$result = execute_stmt($stmt, $link);
while ($row = db_get_row($result)){
$booked[start][] = $row->start_date;
$booked[end][] = $row->expires;
}
$possible_bookings = count($booked[start]);
// would there be more bookings then possible?
if ($possible_bookings >= $places){ // not enough space. Try
nest day
$shift = true; // shift period for one day
$reservation = 1;
$new_start = date("Ymd",strtotime($new_start." + 1 day"));
$new_end = date("Ymd",strtotime($new_end." + 1 day"));
}
else{ // enough space
unset($shift);
}
unset($booked);
} while ($shift); // shift as long as we find free space

############################################################ ####################################



############################################################ ####################################
# if client wants to book all pages, we have to try also the second
constellation
# we could not find a way to do this in one sql query
# find out if booking period has to be shifted even further due to
all pages booking
if ($page == 3){
do{
// get all toplistings that are at least with one day inside
the desired booking period
$stmt= "
SELECT
*
FROM
$DB.$T54
WHERE
cat_id = '$data[cat_id]'
AND cat_type = '$data[cat_type]'
$where_page_2
AND
(
(start_date <= '$new_start' AND expires >=
'$new_start')
OR (start_date <= '$new_end' AND expires >=
'$new_end')
OR (start_date >= '$new_start' AND start_date<=
'$new_end')
)
";
//echo $stmt.$br;
$result = execute_stmt($stmt, $link);
while ($row = db_get_row($result)){
$booked[start][] = $row->start_date;
$booked[end][] = $row->expires;
}
$possible_bookings = count($booked[start]);
// would there be more bookings then possible?
if ($possible_bookings >= $places){ // not enough space. Try
nest day
$shift = true; // shift period for one day
$reservation = 1;
$new_start = date("Ymd",strtotime($new_start." + 1
day"));
$new_end = date("Ymd",strtotime($new_end." + 1 day"));
}
else{ // enough space
unset($shift);
}
unset($booked);
} while ($shift); // shift as long as we find free space
}

############################################################ ####################################


This is rather a dirty solution. Maybe someone has an idea on how to do
it more elegant? I believe there should be one simple line that is
different instead of checking it all over again for a second time.


Any ideas?


Kim Madsen wrote:
> Hey Merlin
>
> Merlin Morgenstern wrote on 2009-12-07 11:52:
>> Hello everybody,
>>
>> I am having trouble finding a logic for following problem:
>>
>> Should be true if:
>> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
>>
>> The result should never contain 1 AND 2 in the same time.
>>
>> This obviously does not work:
>> (page = 1 OR page = 3) OR (page = 2 OR page = 3)
>>
>> This also does not work:
>> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND
>> page != 1)
>>
>> Has somebody an idea how to solve this?
>
> I've read the entire thread and can see that this is a MySQL query you
> want to make (I was about to tell you about the == comparison and the
> $ in a variable in PHP).
>
> What you want is all results containing 1,2 or 3, so make a "WHERE
> page IN(1,2,3)" and use PHP logic to figure out if a free slot is
> available or not. Or rewrite your booking routine (use data and time
> fields instead, maybe by creating a bunch of free slots and then a
> booked field with a default of "0", changed to "1" when booked)
>

--------------010002000300060607070807--