tom7890 Posted February 5, 2015 Author Share Posted February 5, 2015 I was doing it myself but i was going round in circles, barands example was better than what i was doing, so i decided to use that anyways no worries. sorry Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1504990 Share on other sites More sharing options...
CroNiX Posted February 5, 2015 Share Posted February 5, 2015 Nothing to be sorry about. Really. While you are learning, I would just suggest starting with something a lot smaller with a lot less moving parts. You can't just walk in and build a house without knowing and understanding all of the underlying concepts, like first excavating, then building the foundation, plumbing, electrical, etc. Something like a "contacts" application, where you can created/edit/delete single contacts. Then after that's working, get a bit more complex, and allow for things like being able to have multiple children per contact (which would need a secondary db table, and using joins), etc. Start simple and expand it. The purpose of this site isn't to write code/applications for people. It's to help them with individual problems they are having with their own code, when they run into it. Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1504992 Share on other sites More sharing options...
tom7890 Posted February 5, 2015 Author Share Posted February 5, 2015 I have taken on board what you suggested. I have been working on the current code and i have used if (!$res) die($db->error . "<pre>$sql</pre>"); to check all the queries are working properly. I have managed to retrieve the time slots from the database but i have an error, The full code is function bookingForm($db, DateTime $date) { $dt = $date->format('Y-m-d'); $sql = "SELECT t.timeslot_id , TIME_FORMAT(start_time, '%H:%i') , TIME_FORMAT(end_time, '%H:%i') , booking_id , s.staff_id FROM timeslot t LEFT JOIN booking b ON t.timeslot_id = b.timeslot_id LEFT JOIN staff s ON b.staff_id = s.staff_id ORDER BY t.start_time"; $res = $db->query($sql); if (!$res) die($db->error . "<pre>$sql</pre>"); while (list($timeslot_id, $start_time, $end_time, $booking_id, $staff_id) = $res->fetch_row()) { $cbox = $booking_id ? "<input type='checkbox' name='cancel' value='$booking_id'>":''; $cls = $booking_id ? '' : "class='we'"; $staff = $booking_id ? $staff_id : "<select name='staff[$timeslot_id]'>$staffOpts</select>"; $dis = $booking_id ? 'disabled' : ''; echo "<tr> <td $cls>$timeslot_id</td> <td $cls>$start_time</td> <td $cls>$end_time</td> <td $cls>$booking_id</td> <td $cls>$staff_id</td> </tr>\n"; }} The code line in question is: $staff = $booking_id ? $staff_id : "<select name='staff[$timeslot_id]'>$staffOpts</select>"; I have changed it and added in the staff last name as it needs name not id like so, function bookingForm($db, DateTime $date) { $dt = $date->format('Y-m-d'); $sql = "SELECT t.timeslot_id , TIME_FORMAT(start_time, '%H:%i') , TIME_FORMAT(end_time, '%H:%i') , booking_id , s.staff_id , s.lname FROM timeslot t LEFT JOIN booking b ON t.timeslot_id = b.timeslot_id LEFT JOIN staff s ON b.staff_id = s.staff_id ORDER BY t.start_time"; $res = $db->query($sql); if (!$res) die($db->error . "<pre>$sql</pre>"); // ADD THIS LINE HERE while (list($timeslot_id, $start_time, $end_time, $booking_id, $staff_id, $lname) = $res->fetch_row()) { $cbox = $booking_id ? "<input type='checkbox' name='cancel' value='$booking_id'>":''; $cls = $booking_id ? '' : "class='we'"; $staff = $booking_id ? $lname: "<select name='lname[$timeslot_id]'>$lname</select>"; $dis = $booking_id ? 'disabled' : ''; echo "<tr> <td $cls>$timeslot_id</td> <td $cls>$start_time</td> <td $cls>$end_time</td> <td $cls>$booking_id</td> <td $cls>$staff_id</td> </tr>\n"; }} The error has disappeared. I thought id update the post as i cannot delete it. Just for testing purposes i added in a staff member in the database but it is not being retrieved. Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1505003 Share on other sites More sharing options...
CroNiX Posted February 5, 2015 Share Posted February 5, 2015 What error? From what I can see you don't have $staffOpts defined anywhere. Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1505004 Share on other sites More sharing options...
tom7890 Posted February 5, 2015 Author Share Posted February 5, 2015 sorry i forgot the add the error, the error was $staffOpts was not defined Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1505006 Share on other sites More sharing options...
CroNiX Posted February 5, 2015 Share Posted February 5, 2015 Do you know how to make a <select> element, with <option>'s? You have no <options>. You're creating <select>$lname</select> over and over in a loop....but no options Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1505008 Share on other sites More sharing options...
tom7890 Posted February 5, 2015 Author Share Posted February 5, 2015 Do you know how to make a <select> element, with <option>'s? You have no <options>. You're creating <select>$lname</select> over and over in a loop....but no options yes i do like so <html> <body> <select> <option value="tom">tom</option> <option value="gabi">gabi</option> <option value="php">php</option> </select> </body> </html> But the options in my code need to be retrieved from the database Link to comment https://forums.phpfreaks.com/topic/293995-php-sql-calendar-add-events/page/6/#findComment-1505013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.