Page 1 of 1

Select Query

Posted: Sat Aug 29, 2009 4:33 pm
by zed420
Hi All
I've been struggling with this query for past 4days now see If anyone can help me please. A typical day's diary starts from 8am till 9pm, normally you would book an hr but just to test the script I booked 8am to 9pm so that means all day has been booked NO other booking can be taken for this day if I DO NOT select the varibles 8 & 9 IT WILL book again and again . ????? why why?????
Thanks Zed

Code: Select all

    $query = "SELECT b_id, COUNT(*) AS Cnt 
FROM booking 
WHERE request_date='$request_date' 
AND e_time > '$s_time' 
AND s_time < '$e_time' 
GROUP BY b_id"; 
    $result = mysql_query($query); 
    $row = mysql_fetch_assoc($result);
    if($row['Cnt'] > 0){ 
    error_message('Sorry, this time is already booked. Please choose another');
            } else { 
 

Re: Select Query

Posted: Sat Aug 29, 2009 4:45 pm
by requinix
You are using a 24-hour clock, right? Are e_time and s_time numbers or date/times?

Re: Select Query

Posted: Sat Aug 29, 2009 9:31 pm
by zed420
Thanks for your reply, Numbers

Re: Select Query

Posted: Sat Aug 29, 2009 9:53 pm
by requinix
And a 24-hour clock? So you count 0-23 or 1-24?

Re: Select Query

Posted: Sat Aug 29, 2009 10:14 pm
by zed420
1 to 24 this is the JavaScript I'm using to generate this

Code: Select all

<script type="text/javascript">
 
window.onload = function() {
var s = document.booking_form.s_time;
var e = document.booking_form.e_time;
s.selectedIndex = 0; 
e.selectedIndex = 1; 
s.onchange = function() { 
 
for(var i = 1; i < e.options.length; i++) {
            e.options[i].removeAttribute('disabled');
        }
        var val = s.options[s.selectedIndex].value;
        if(val < 24) { 
            for(var i = 1; i <= val; i++) {
                (function() {
                    e.options[i-1].disabled = "disabled";
                })();
            }
            e.selectedIndex = val;
        }
    }
}
 
</script>
 

Re: Select Query

Posted: Sun Aug 30, 2009 4:01 pm
by Ollie Saunders
It's never done 1-24; always 0-23. You'd need a pretty good reason to deviate.