My time slots aren't booked
Results 1 to 3 of 3

Thread: My time slots aren't booked

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1

    My time slots aren't booked

    Hello guys. I'm new to this Forum. So I hope that I'm posting in the right place.

    Here's wats up:
    I want to create a basic time slot booking system. But I've run into some problems.

    I have created a calendar where I can see that something is happening on a speific date:

    event2.png

    It takes the information from my database table:

    event.png

    But as you can see in the table, I would also like to use a start time and an endtime.

    If I click a date, I create the add-event link like this:

    Code:
    <?php
    	if (isset ( $_GET ['v'] )) {
    		echo "<a href='test.php . ?month=" . $month . "&day=" . $day . "&year=" . $year . "&v=true&f=true'>Add Event</a>";
    		if (isset ( $_GET ['f'] )) {
    			include ("test.php");
    		}
    		$sqlEvent = "SELECT * FROM calendar WHERE eventDate='" . $month . "/" . $day . "/" . $year . "'";
    		$resultEvents = mysqli_query ( $mysqli1, $sqlEvent );
    		echo "<br>";
    		while ( $events = mysqli_fetch_array ( $resultEvents ) ) {		
    		}
    	}
    	?>
    My test.php:

    Code:
    <?php 
        $hostname = 'localhost';
        $username = 'root';
        $password = '';
        $dbname = "calendar";
        
        $error = 'Cannot connect to the database';
        
        $mysqli1 = new mysqli ( $hostname, $username, $password, $dbname ) or die ( $error );
        
        if (isset ( $_GET ['day'] )) {
        	$day = $_GET ['day'];
        } else {
        	$day = date ( "j" );
        }
        
        if (isset ( $_GET ['month'] )) {
        	$month = $_GET ['month'];
        } else {
        	$month = date ( "n" );
        }
        
        if (isset ( $_GET ['year'] )) {
        	$year = $_GET ['year'];
        } else {
        	$year = date ( "Y" );
        }
        
        $dateToCompare = $month . '/' . $day . '/' . $year;
        
            echo "<br/><br/><h3>Reservations</h3>";
            $timearray =  array(8,9,10,11,12,13,14,15,16,17,18,19,20,21,22);
            $tablecolor = 1;
            echo "<table style='width: 90%;'>";
            echo "<tr>";
                echo "<th>";
                    echo "Time";
                echo "</th>";
                echo "<th>";
                    echo "Status";
                echo "</th>";
        
            echo "</tr>";
            foreach ($timearray as $timearrays) {
                if($tablecolor %2 == 0) {
                    echo "<tr>";
                }
                else {
                    echo "<tr style='background-color: rgb(0,100,255); background: rgb(0,100,255);'>";
                }
        
                    echo "<th>";
                    if ($timearrays == 8) {echo "<h3>8-9am</h3>";}
                    if ($timearrays == 9) {echo "<h3>9-10am</h3>";}
                    if ($timearrays == 10) {echo "<h3>10-11am</h3>";}
                    if ($timearrays == 11) {echo "<h3>11-12am</h3>";}
                    if ($timearrays == 12) {echo "<h3>12-13am</h3>";}
                    if ($timearrays == 13) {echo "<h3>13-14am</h3>";}
                    //Develop your timeslots here to display as required
                    echo "</th>";
                    echo "<td>";
                    
                    $sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
                    
                    $result = mysqli_query($mysqli1,$sql);
                    
                    if (mysqli_num_rows($result) == 0) {
                        echo "<a href='#'><h3 style='color: rgb(255,0,0);'>Reserve</h3></a>";
                    } else {
                        echo "<h3>Not Available, taken by someone</h3>";
                        while($row = mysql_fetch_array($result)) {
                            echo "<br />";
                        }
                    }
                    echo "</td>";
                echo "</tr>";
                $tablecolor++;
            }
            echo "</table>";
        
        ?>
    As you can see, I try to display my timeslots:
    Code:
    `$sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";`
    I think that I get my dates correctly from the URL, but I don't see any reservations for a given date.

    event3.png

    I hope that some of you can help me out. And please ask, if I need to provide more of my code.

  2. #2
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,708
    Debugging idea:

    1. Have the script print the SQL statement yielded by this:
    PHP Code:
    `$sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
    2. Plug that statement into your PHPMyAdmin's "SQL" tab/window and try the query.

    I dunno if this will help, but it's something to check before we going chasing elsewhere....
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  3. #3
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,708
    And wow ... why did this show up in "New posts" ... since it's about 2 weeks old....

    Hopefully you got it sorted....
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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