Select Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zed420
Forum Commoner
Posts: 32
Joined: Wed Jun 04, 2008 11:24 am

Select Query

Post 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 { 
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Select Query

Post by requinix »

You are using a 24-hour clock, right? Are e_time and s_time numbers or date/times?
zed420
Forum Commoner
Posts: 32
Joined: Wed Jun 04, 2008 11:24 am

Re: Select Query

Post by zed420 »

Thanks for your reply, Numbers
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Select Query

Post by requinix »

And a 24-hour clock? So you count 0-23 or 1-24?
zed420
Forum Commoner
Posts: 32
Joined: Wed Jun 04, 2008 11:24 am

Re: Select Query

Post 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>
 
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Select Query

Post by Ollie Saunders »

It's never done 1-24; always 0-23. You'd need a pretty good reason to deviate.
Post Reply