Try putting brackets round the date selection part. I think the database
treats AND with a higher precedence than OR, and evaluates ANDs first.
So what your query is doing is like

A OR (B AND C)

But what you want is

(A OR B) AND C

Where 

A is '$book_start_date' BETWEEN booking_start AND booking_end
B is '$book_end_date' BETWEEN booking_start AND booking_end
C is villa_id = '$place'

HTH,

Richy

==========================================
Richard Black
Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com
Tel: 0141 435 3504
Email: [EMAIL PROTECTED] 

-----Original Message-----
From: Ray Healy (Data Net Services) [mailto:[EMAIL PROTECTED]] 
Sent: 28 August 2002 17:49
To: [EMAIL PROTECTED]
Subject: [PHP] Help with script - if possible


Hi All

Thanks for everyones help in trying to get my script to work - I'm
learning fast. But have the following problem:

I am using the following select command for searching a table with
regards to booked villas according to id number:

$sql = "SELECT COUNT(*) as count FROM bookings WHERE '$book_start_date'
BETWEEN booking_start AND booking_end OR '$book_end_date' BETWEEN
booking_start AND booking_end AND villa_id = '$place'";

This counts as far as I believe an displays a "0" if available and
"number of times it occurs" if unavailable.

The problem I have is that still counts the number of entries regardless
of the villa_id number it is given. In other words if I have a villa
that is booked between 2002-04-10 and 2002-004-20 for villa_id 1 and I
search using the same dates (via a FORM) but on villa_id 3 it still
comes back and says that the villas is unavailable. Which of course it
is wrong for villa_id 3 (it is villa_id 1 that is booked).

I have tried to find a command (something like IF villa_id =3 THEN
count) but to no avail that would only count if the villa_id matches as
well.

Can anyone help

Thanks for your time.


Ray


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


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

Reply via email to