Jump to content

php sql calendar add events


tom7890

Recommended Posts

  • Replies 131
  • Created
  • Last Reply

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.

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. 

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 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.