php-general Digest 7 Dec 2009 20:03:58 -0000 Issue 6475

Topics (messages 300263 through 300286):

Re: includes linking to other files, help with relatives
        300263 by: Midhun Girish

logic operands problem
        300264 by: Merlin Morgenstern
        300265 by: Devendra Jadhav
        300266 by: Merlin Morgenstern
        300267 by: Thales Jacobi
        300268 by: Peter Ford
        300269 by: Ashley Sheridan
        300270 by: Merlin Morgenstern
        300271 by: Merlin Morgenstern
        300272 by: Ashley Sheridan
        300273 by: Sándor Tamás (HostWare Kft.)
        300274 by: Merlin Morgenstern
        300275 by: Merlin Morgenstern
        300276 by: Merlin Morgenstern
        300277 by: Ashley Sheridan
        300278 by: Lester Caine
        300279 by: Ford, Mike
        300280 by: Ashley Sheridan
        300282 by: Ford, Mike
        300283 by: Kim Madsen
        300284 by: tedd
        300285 by: Merlin Morgenstern

Live PHP Code Templates for NetBeans - accelerate your php development.
        300281 by: Raymond Irving

mysterious include problem
        300286 by: Allen McCabe

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hello Allen McCabe,

it doesnt matter from which folder you call the database.php file..... only
thing u must take care is to use correct path in the database.php file so
that key.txt is accurately referenced..... if you are still having problems,
use absolute paths instead of relative path...hers a reference
http://www.ibdhost.com/help/path/.... GL...


Midhun Girish


On Mon, Dec 7, 2009 at 11:17 AM, Allen McCabe <[email protected]> wrote:

> I am creating a database connection path that check for a session variable
> to get the username, password, dbname, etc., but if the session has not
> been
> set yet, I need my script to get those values from another file
> (KEY.txt) where they are saved. I want to access this class from two
> directories, and this text file (KEY.txt) is in a directory above both.
> Like
> this:
>
> root: folder1 - folder2
>
> folder1: KEY.txt
>
> folder2: index.php - database.php - folder3
>
> folder3: index.php
>
> I need to use database.php in both index files, but database.php references
> KEY.txt. So my question is, do I have to check which directory the calling
> script is in (ie. which index.php file is using database.php) and add the
> according up directory references, or do I need to use some kind of
> $_SERVER[DOCUMENT_ROOT]
> thing?
>
> Any help would be appreciated!
>

--- End Message ---
--- Begin Message ---
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

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

On Mon, Dec 7, 2009 at 4:22 PM, Merlin Morgenstern <[email protected]>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
देवेंद्र जाधव

--- End Message ---
--- Begin Message ---


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 <[email protected] <mailto:[email protected]>> 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
देवेंद्र जाधव

--- End Message ---
--- Begin Message ---
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" <[email protected]> wrote in message news:[email protected]...
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


--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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



--- End Message ---
--- Begin Message ---

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

--- End Message ---
--- Begin Message ---

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

--- End Message ---
--- Begin Message ---
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



--- End Message ---
--- Begin Message --- 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" <[email protected]>
To: "Merlin Morgenstern" <[email protected]>
Cc: "Peter Ford" <[email protected]>; <[email protected]>
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





--- End Message ---
--- Begin Message ---


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?


--- End Message ---
--- Begin Message ---


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?
--- End Message ---
--- Begin Message ---


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" <[email protected]>
To: "Merlin Morgenstern" <[email protected]>
Cc: "Peter Ford" <[email protected]>; <[email protected]>
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





--- End Message ---
--- Begin Message ---
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



--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Merlin Morgenstern [mailto:[email protected]]
> Sent: 07 December 2009 11:52
> To: "Sándor Tamás (HostWare Kft.)"
> Cc: Merlin Morgenstern; [email protected]
> Subject: Re: [PHP] Re: logic operands problem
> 
> 
> 
> 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?

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 sets 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 be 
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 does 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=1 OR page=2 OR page=3), which, as 
you found, returns your entire database.

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: [email protected] 
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

--- End Message ---
--- Begin Message ---
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.html


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



--- End Message ---
--- Begin Message ---
Um, yes, probably need to update my Oracle reference manuals – I think the big 
fat paper one on my shelf may even refer to ANSI SQL89, which I suspect is 
pretty much what my head content is based on also. In any case, XOR doesn’t 
appear to be in the latest ANSI/ISO SQL standards I have access to (ANSI 2003), 
so this may be a MySQL-specific extension.

 

But however you slice it, XOR is the wrong solution for the problem at hand! ;)


Cheers!

Mike

 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: [email protected] 
Tel: +44 113 812 4730

 

 

 

From: Ashley Sheridan [mailto:[email protected]] 
Sent: 07 December 2009 12:26
To: Ford, Mike
Cc: [email protected]
Subject: RE: [PHP] Re: logic operands problem

 

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.html



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



 



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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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)


--- End Message ---
--- Begin Message ---
Hello Everyone,

I've made a few code templates (HTML, PHP)  available for everyone to
download and use with NetBeans 6.7 or higher. It will greatly
accelerate your php development.

http://code.google.com/p/raxan/downloads/detail?name=code-templates.zip&can=2&q=

And if your interested in further accelerating your PHP/Ajax
development, then you might want to check out the new and improved
Raxan for PHP (http://raxanpdi.com/)

__
Raymond Irving
Raxan for PHP - Ajax just got a whole lot easier!

--- End Message ---
--- Begin Message ---
I have been using includes for my content for a while now with no problems.
Suddenly it has stopped working, and it may or may not be from some changes
I made in my code structure.

I use default.php for most or all of my pages within a given directory,
changing the content via page numbers in the query string.


So on default.php, I have the following code:


<?php
if(isset($_GET['page']))
{
  $thispage = $_GET['page'];
  $content = 'content/'.$_GET['page'].'.inc';
}
else
{
  $thispage = "default";
  $content = 'content/default.inc';
}
?>
<html>, <body>, <div> etc.
<?php include($content); ?>


I have a content subdirectory where I store all the pages with files such as
"default.inc, 101.inc, 102.inc, etc.

As I said, this has been working fine up until now, if I use the url
"user/default.php" or just "user/" I get this error:


*Warning*: include(content/.inc)
[function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
failed to open stream: No such file or directory in *
/home/a9066165/public_html/user/default.php* on line *89*

AND

*Warning*: include()
[function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
Failed opening 'content/.inc' for inclusion
(include_path='.:/usr/lib/php:/usr/local/lib/php') in *
/home/a9066165/public_html/user/default.php* on line *89*

But if I use "user/default.php?page=default"  I get the correct content.

It's acting as if page is set, but set to NULL, and then trying to find an
include at path "content/.inc"  what's going on??

--- End Message ---

Reply via email to