SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast nerf's Avatar
    Join Date
    May 2004
    Location
    Sunshine Coast, Australia
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date & time Schedule system

    Hello,

    Im creating a booking system which shows a table of time slots which indicate which person(across top) is being booked for what time(going down).

    I have a table for users, the time frames available and the following code which appears to run fine, although my query which checks to see if a time is booked doesnt seem to work properly. The code is as follows:

    PHP Code:
     include("DBconn.php");
    $depts mysql_query("SELECT * FROM departments");
    $hour_list mysql_query("SELECT * FROM list_hours");
    $bk "SELECT * FROM bookings WHERE ";
    if (!isset(
    $_REQUEST["day"])){
    $date date("Y-m-j");
    }else{
    $date $_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["day"];}
    echo 
    "<table width='100%'>";
    while(
    $hours mysql_fetch_array($hour_list)) {
    echo 
    "<tr><td bgcolor=#FFFFFF><font size=1>".substr($hours["hours"],0,5)."</font></td>"
    $mechs mysql_query("SELECT * FROM mechs ORDER BY dept ASC");
    while(
    $mech mysql_fetch_array($mechs)) {
    $bookings mysql_query($bk."time_start <= '".$date." ".$hours["hours"]."' & time_finish > '".$date." ".$hours["hours"]."' & mech = ".$mech["ID"]);
    if (
    $bookings) {
        echo 
    "<td width='100' bgcolor='#FF0000'></td>";
    }else{
        echo 
    "<td width='90' bgcolor='#FF00FF'><font size=1></font></td>"; }
        echo 
    mysql_error(); }
    echo 
    "</tr>"; }
    echo 
    "</table>"

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    What errors do you get, if any?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast nerf's Avatar
    Join Date
    May 2004
    Location
    Sunshine Coast, Australia
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No errors at all...

    the section of code here is supposed to create a cell in the table to show if its booked or not, in this instance changing its background color

    PHP Code:
    $bookings mysql_query($bk."time_start <= '".$date." ".$hours["hours"]."' & time_finish > '".$date." ".$hours["hours"]."' & mech = ".$mech["ID"]);
    if (
    $bookings) {
        echo 
    "<td width='100' bgcolor='#FF0000'></td>";
    }else{
        echo 
    "<td width='90' bgcolor='#FF00FF'><font size=1></font></td>"; }
        echo 
    mysql_error(); } 
    and nothing comes out from the "echo mysql_error();" either.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    It looks like you are querying the $bookings but not retrieving any data.
    Will have a look into it for you!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Enthusiast nerf's Avatar
    Join Date
    May 2004
    Location
    Sunshine Coast, Australia
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if it helps, where i have:
    "if ($bookings) {"
    if i change it to "if (!$bookings) {" it reverses the result, so im not sure
    what result the query brings back, either way every cell in the table is the same color, no seperately shaded cells.

    thanks!

  6. #6
    SitePoint Enthusiast nerf's Avatar
    Join Date
    May 2004
    Location
    Sunshine Coast, Australia
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i ran a test on the $bookings query outside of that script.
    PHP Code:
    $ss mysql_query($bk."time_start = '2004-12-13 08:15:00' & time_finish > '2004-12-13 08:15:00' & mech = 1");
    while (
    $s mysql_fetch_array($ss)){
    echo 
    $s["first_name"]." ".$s["last_name"]; } 
    Is what i used and it prints nothing, but when i used:
    PHP Code:
    $ss mysql_query($bk."time_start = '2004-12-13 08:15:00' & time_finish = '2004-12-13 11:30:00' & mech = 1");
    while (
    $s mysql_fetch_array($ss)){
    echo 
    $s["first_name"]." ".$s["last_name"]; } 
    with the finish_time = to its actual value, it works.

    Is my code for querying if the date is larger than, incorrect ?

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Try the query with => or >= and see what happens.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Enthusiast nerf's Avatar
    Join Date
    May 2004
    Location
    Sunshine Coast, Australia
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it seems my query isnt working correctly at all...
    even if i set the field names = to anything it gives a result....
    but if its using '>' or '<' then it doesnt work at all.

    and also if i echo the original query "echo $ss;" it returns something like "Resouce ID #581"

    The field type is 'datetime' which i assumed was the best choice for working with date and time. i dont understand why when querying it, it doesnt seem to query that field correctly.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •