Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. $_SESSION variables are global. Have you got session_start() at the top of the page?
  2. These are mine: CREATE TABLE `user` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(25) DEFAULT NULL, `email` varchar(100) DEFAULT NULL, `phone` varchar(15) DEFAULT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `timeslot` ( `timeslot_id` int(11) NOT NULL AUTO_INCREMENT, `start_time` time DEFAULT NULL, `end_time` time DEFAULT NULL, PRIMARY KEY (`timeslot_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `booking` ( `booking_id` int(11) NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `timeslot_id` int(11) DEFAULT NULL, `user_id` int(11) DEFAULT NULL, `comments` varchar(255) DEFAULT NULL, PRIMARY KEY (`booking_id`), KEY `IDX_time` (`timeslot_id`), KEY `IDX_user` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  3. What does this output (in PhpMyAdmin for example)? SHOW CREATE TABLE timeslot;
  4. Let's see if the query failed, and if it did, why $books = array(); $res = $db->query($sql); if (!$res) die($db->error . "<pre>$sql</pre>"); // ADD THIS LINE HERE while (list($dt,$tot,$free) = $res->fetch_row()) { $books[$dt] = array($tot, $free); } return $books;
  5. This is a really frightening thought - their lives in your hands You are going to need that for the bookings. What I said is you should hve generated that by looping though the records in the timeslot table and not by hard coding every start and end time. You do that when you generate the calendar.
  6. Your bookings table should contain date timeslot_id so you then know which slots are booked each day
  7. If the week changes then the week start and end of week dates will need to be changed by +/- 7 days $wkstart = '2015-01-18'; $wkstart = date('Y-m-d', strtotime("$wkstart +7 days")); echo $wkstart; //--> 2015-01-25
  8. You only need to record slots that are booked in the database booking table, not the calendar.
  9. No, you didn't. You changed it from a mysqli connection to a mysql connection. Just change the credentials USERNAME PASSWORD DATABASENAME mysql_xxxxx functions are deprecated and will be withdrawn from PHP.
  10. All you had to change was this line - note the comment $db = new mysqli('localhost', 'user', 'pwd', 'db'); // use your credentials
  11. Make the timeslot id auto_increment This is the code I have just used to populate my version of the timeslot table with 15 min timeslots $db = new mysqli('localhost', 'user', 'pwd', 'db'); // use your credentials $sql = "TRUNCATE TABLE timeslot"; $db->query($sql); $dt1 = new DateTime("09:00:00"); $dt2 = new DateTime("09:15:00"); $di = new DateInterval('PT15M'); $dp = new DatePeriod($dt1, $di, new DateTime('18:00:00')); $sql = "INSERT INTO timeslot(start_time, end_time) VALUES (?,?)"; $smt = $db->prepare($sql); $smt->bind_param('ss', $st,$et); foreach ($dp as $d) { $st = $d->format('H:i'); $et = $dt2->format('H:i'); $dt2->add($di); $smt->execute(); } ?> Done
  12. Your timeslot table would not have a date - it is to define the daily times. You booking table would contain the date and the booked timeslot. See my diagram that i posted earlier http://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/?do=findComment&comment=1503204
  13. Yes. You would use the on change event to send an AJAX request to the server and return a value to let you know if is taken or not.
  14. Avoid problems with spaces and lowercase entirely by restructuring your array $cakesmade = array( "kate" => array( 0=>array( "cakename" => "cake", "cakeingredients" => "egg, flour" ), 1=>array( "cakename" => "Lovely Chocolate Cake", "cakeingredients" => "chocolate, eggs, flour" ), 2=>array( "cakename" => "amazing cake", "cakeingredients" => "lemons, flour" ) ) );
  15. ... WHERE DATE(departure_date_time) = CURDATE()
  16. You said you wanted the chart on the same page
  17. No problem now we have established that works <?php $dir = './data/test111'; $ddArray1 = scandir($dir,1); ?> <html> <head> <title>Select Drop Down List</title> </head> <body> <form action="" method="get"> <select name="file"> <?php FOREACH($ddArray1 AS $file){ PRINT '<option value="'.$file.'">'.$file.'</option>'; } ?> </select> <input type="submit"/> </form> </body> </html> <?php if (isset($_GET['file'])) { $id = $_GET['file']; echo "<img src='mygraph.php?file=$id' />" ; } ?>
  18. Don't output a checkbox for times already booked. If you look at the booking form in the code I gave you you will see it only allows input for non-booked times (except for a cancellation checkbox). And add a unique key on (date, starttime) in the booking table to prevent duplicates. Add a hidden input field to your form containing the date value <input type="hidden" name="date" value="2015-01-22" /> then you can access with $_POST['date'] Why are you hard-coding all those start times in your form instead of pulling them from a timeslot table in the db? Again, if you look at my code you will see it uses a query with FROM timeslot LEFT JOIN booking so you know all the timeslots and which timeslots have/not been booked for the day
  19. No guarantees, but try putting the php portion of your code in a separate file (mygraph.php) and use GET instead of post. In a separate php file put $id = whatever; echo "<img src='mygraph.php?file=$id' />";
  20. Your join() isn't putting the statuses in quotes. It will give IN (active,inactive,un-verified,cheater)
  21. By using the "text-align" attribute in the cells style definition. https://developer.mozilla.org/en-US/docs/Web/CSS/text-align
  22. You can format it in your query EG SELECT DATE_FORMAT(datecol, '%d.%m.%Y') as formatted_date or you can do it in php echo date('d.m.Y', strtotime($row['datecol']));
  23. I set up styles with 3 background colours pale green - default, no bookings yellow - partially booked days red - fully booked days td { background-color: #C4E5C4; } td.full { background-color: red; color: white; font-weight: 600; } td.partial { background-color: yellow; color: black; font-weight: 600; } This the relevant code to apply those classes if (isset($bookings[$d->format('Y-m-d')])) { // are there bookings in db for that day? $tit[$dow] = wordwrap($bookings[$d->format('Y-m-d')][1],34); // construct popup of free times (on hover) if ($bookings[$d->format('Y-m-d')][1]) // are there free slots? $clsArray[$dow] = "class='day partial $now'"; // if so, apply "partial" class else $clsArray[$dow] = "class='day full $now'"; // if not, apply "full" class }
  24. Do you want me to answer that here or in that (yet another) thread you have now raised?
  25. The code I gave you in your original thread on this topic (you now have 3 of them) showed you how to colour code your cells and almost all the other things you said you wanted (like showing available times on hovering, making the cells clickable, displaying a booking form for the clicked day). Look at the code, the answers are there.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.