Time slot booking calendar

Perfect… Here is what I have now…



	$sql = mysql_query("SELECT DATE_FORMAT( timeslot, '%l:%i') as times FROM timeslots WHERE DATE(timeslot) = '$slot'");
	$num_rows = mysql_num_rows($sql);
		while ($row = mysql_fetch_array($sql)) {
			$times[] = $row['times'];
		}


I had to alter the hour variable to drop the leading 0… ie 01:00 apposed 1:00

I guess the main advantage to date_format() aposed to concat() is the ability to format the date result?

Yea the table and field name are very similar… maybe bad practice, I try to name my tables and fields relative so they are easy to remember while writing the code to interact with the tables.

Nah, not bad practice, I just thought I’d mention the similarity because I nearly tripped up on it and wondered if it was a typo - that was all.

Anyhow, I am relieved you seemingly have this working … let us know if there are any other drawbacks you come across.

ps you shouldn’t need to loop through this array:


        while ($row = mysql_fetch_array($sql)) { 
            $times[] = $row['times']; 
        } 

Simply assign it the variable name you want to use (unless you are doing something else which you are not showing)


        $times = mysql_fetch_array($sql)) ;

That’s untested though, as I don’t use the native mysql_* functions myself.

Thanks for that… I have removed the loop.

I also want to display the clients name etc that have appointments on the selected date and display info on the same screen the above query is being displayed on. At the moment I have built a seperate query.



	   $sql = mysql_query("SELECT c.*, t.*
			FROM clients as c
			JOIN timeslots as t ON t.clientid = c.clientid
			WHERE DATE(t.timeslot) = '$slot'
			ORDER BY t.timeslot ASC") or die (mysql_error());
				while ($row = mysql_fetch_array($sql)) {
					foreach($row as $key=>$value){
						$$key = ValidateOutput($value);
					}


Would it be plusable to put the 2 querys into a single one or keep them as seperate querys?

Cheers

I had a feeling you’d be asking that … :wink:


SELECT c.*, t.*  

Get rid of the *s, it is generally frowned upon, as it gets everything - which is wasteful.

Also, I cannot see what fields you are getting back, so cannot advise you.

if it is a clients name, then use c.first_name, c.second_name and so on.

Then show us a typical result set from this query.

To give us a usable array, use:


$d = var_export($row);
echo $d;

1 Like