Page 1 of 1
How to build a little appointment manager?
Posted: Thu Jun 07, 2007 2:13 am
by ianhull
hi Guys,
I would like to build a little appointment manager but I don't know where to start.
I have had a look thought the forum and the php.net/date manual but I cannot work out how to make one of these things.
Not sure if this table will display correctly in the forum.
Code: Select all
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td align="center">Time</td>
<td>Mon DATE</td>
<td>Tue DATE</td>
<td>Wed DATE</td>
<td>Thu DATE</td>
<td>Fri DATE</td>
<td>Sat DATE </td>
<td>Sun DATE</td>
</tr>
<tr>
<td align="center">8am</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center">9 am</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center">10 am</td>
<td> </td>
<td>appointment at somewhere blah blah.</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center">11 am</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center">12 noon</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center">1 pm</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center">2 pm</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
Can anyone provide me with any advise on where to get started.
Any samples?
thanks
Posted: Thu Jun 07, 2007 2:43 am
by ianhull
Can anyone help me to get the days and day dates together?
I could do with Thu 7th Fri 8th etc.
thanks
Posted: Thu Jun 07, 2007 3:14 am
by onion2k
It can all be done with date(), strtotime() (or mktime() ), and a loop.
Posted: Thu Jun 07, 2007 5:05 am
by ianhull
thanks onion2k,
I suppose what I really need is a week view calendar,
After looking through the php.net/date manual and mktime I cannot work out how to get everything into the format that I need.
Does anyone have any samples of week view that I could see to try and understand it a little more.
All I need is a table header view of the next seven days
i.e; | Monday 4th | Tuesday 5th | Wednesday 6th | Thurdays 7th | Friday 8th | Saturday 9th | Sunday 10th |
if anyone can help me achieve this it will be greatly appreciated.
Thanks in advance.
Posted: Thu Jun 07, 2007 7:23 am
by feyd
Posted: Thu Jun 07, 2007 7:35 pm
by ianhull
feyd,
thanks for your help with that,
I have now managed to get the display correct.
My issue now is.
I have placed 1 entry into my database using appointment_day 10 month 6 and year 2007
but when I query the database, it places my entry on the 18th of june
Here is what I have, can anyone see why this is happening?
Code: Select all
<link href="../styles/index.css" rel="stylesheet" type="text/css" />
<table width="96%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td width="20%">Date:</td>
<td width="66%">Details:</td>
<td width="7%"> </td>
<td width="7%"> </td>
</tr>
<tr>
<?php
$month = date('n');
$year = 2007;
$total_months = 12;
$i = 0;
while($i <= date('t')){
$time = time() + ($i * 24 * 60 * 60);
echo '<td class="calendar-numbers">'.date('l jS', $time).'</td>';
echo '<td class="appointments-list">';
$getAppointments = mysql_query("SELECT
id,
appointment_day,
appointment_month,
appointment_year,
appointment_time,
company_name,
assigned_to_firstname,
assigned_to_surname FROM appointments WHERE appointment_day = '$i' AND appointment_month = '$month' AND appointment_year = '$year'")or die(mysql_error());
while($appointmentsRecieved = mysql_fetch_array($getAppointments)){
extract($appointmentsRecieved);
echo $company_name.'1';
}
echo '</td>
<td> </td>
<td> </td></tr>';
$i++;
}
?>
</table>
thanks in advance.
Posted: Thu Jun 07, 2007 7:59 pm
by bdlang
Not to be critical, but you make 28 ~ 31 calls to mysql_query() in that loop, depending on how many days a given month has. To top that off, you retrieve all the column data in the resultset (storing it in a double-indexed array) and proceed to display 1 value from that. I understand if this is a first effort, believe me, but this is extremely ineffiecient. Imagine if you had more than just 1 record to retrieve.
A much better way to do this is to make 1 call to mysql_query(), retrieving data and storing it in an array. Then loop through the days and if a certain date matches, display the data for that date. Perform your MySQL tasks outside (before) the loop. You should also consider using a single DATETIME type column to store the date.
As to the problem you inquired about, have you checked the data manually to make sure it's set to the proper date? Do the calendar day values show properly?
Shouldn't $i be initialized to 1?
Posted: Thu Jun 07, 2007 9:24 pm
by ianhull
Yes your right,
it is a bit overwhelming, all the calls t the db,
It is my first attempt, however, I have taken your advise and now I have this.
Code: Select all
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/connection.php');
$getAppointments = mysql_query("SELECT
id,
appointment_day,
appointment_month,
appointment_year,
appointment_time,
company_name,
assigned_to_firstname,
assigned_to_surname FROM appointments")or die(mysql_error());
while($appointmentsRecieved = mysql_fetch_array($getAppointments, MYSQL_ASSOC)){
foreach ($appointmentsRecieved as $made_appointments[]){
}
}
$diary_dates = array();
$i = 0;
while($i <= date('t')){
$time = time() + ($i * 24 * 60 * 60);
$diary_dates[''.$i.''] = date('l jS', $time);
$i++;
}
exit();
foreach ( $made_appointments as $key => $val )
echo "<p>{$key}: {$val}</p>";
?>
One thing I am stuck with now though is merging them correctly, any ideas how i would achieve this?
I have had a look at array_search("what im looking for", $the_array_to_search_in);
but I am not sure how to do it.
Any help greatly appreciated.
thanks in advance.
Posted: Thu Jun 07, 2007 10:42 pm
by bdlang
Something more like
Code: Select all
// your query, 'slightly altered'
$getAppointments = mysql_query("
SELECT
id,
CONCAT(appointment_year,appointment_month,appointment_day) AS the_date,
appointment_time AS time,
company_name,
CONCAT(assigned_to_firstname,' ',assigned_to_surname) AS assigned_to_name
FROM appointments")
or die(mysql_error());
// empty array to hold the formatted entries from the resultset
$diary_entries = array();
// retrieve the resultset and fill the diary_entries array
while($row = mysql_fetch_array($getAppointments, MYSQL_ASSOC)){
// 20070607 => array( 0 => 'Company X', 1 => 'Bob Smith' )
$diary_entries[ $row['the_date'] ]= array($row['company_name'], $row['assigned_to_name'], $row['time']);
}
Test the returning array with var_dump() to see the contents prior to creating your calendar / date book.
Your loop to create the date entries checks the entries in $diary_entries like so:
Code: Select all
for ( $i=1; $i<= date('t'); $i++ ) {
// display your <td> and date, etc
// workaround to create a day value like 01|02|03|etc
$j= ($i < 10) ? '0'.$i : $i;
// create a date entry for this specific year month day
$this_day= date('Ym'.$j);
// check to see if this specific date has an entry
if ( isset($diary_entries[$this_day]) ) {
// if so, display the company_name and assigned_to_name and time values
echo $diary_entries[$this_day][0] .'<br />'. $diary_entries[$this_day][1] .'<br />'. $diary_entries[$this_day][2];
}
// </td> and whatever else you need to display
}
Hope I didn't lose you there in that loop.

Posted: Fri Jun 08, 2007 9:56 am
by ianhull
Thank for that,
much appreciated,
I have managed to do what I wanted and it all works now.
I didn't use your code as it was a bit over my head
This code now works....but,
If there is no appointments listed it does not display the diary dates so that someone can add an appointments
it just shows the table header.
any ideas?
thanks in advance
Code: Select all
<link href="../styles/index.css" rel="stylesheet" type="text/css" />
<?php
echo '<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td class="calendar-numbers">Dates:</td>
<td class="appointments-list">Appointment Details:</td>
<td>Modify</td>
<td>Add New Appointment</td>
</tr>
<tr>';
$diary_dates = array();
if(isset($_GET['month'])){
$month = $_GET['month'];
} else {
$month = date('n');
};
if(isset($_GET['year'])){
$year = $_GET['year'];
} else {
$year = date('Y');
};
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/connection.php');
$getAppointments = mysql_query("SELECT
* FROM appointments WHERE appointment_month = '$month' AND appointment_year = '$year' AND assigned_to_firstname = '$firstname' AND assigned_to_surname = '$surname' ORDER BY appointment_day")or die(mysql_error());
while($appointmentsRecieved = mysql_fetch_array($getAppointments, MYSQL_ASSOC)){
$i = 0;
while($i <= date('t')){
$time = mktime(0,0,0,$month, $i, $year);
$diary_dates[''.$i.''] = date('l jS', $time);
echo '<td class="calendar-numbers">'.$diary_dates[''.$i.''].'</td>';
if($appointmentsRecieved['appointment_day'] == $i){
echo '<td class="appointments-list">'.$appointmentsRecieved['company_name'].' '.$appointmentsRecieved['appointment_time'].' '.$appointmentsRecieved['city'].' '.$appointmentsRecieved['county'].' '.$appointmentsRecieved['postcode_1'].' '.$appointmentsRecieved['postcode_2'].'</td>
<td>Modify Link</td>
<td>Add New Link</td>
<tr>';
} else {
echo '<td class="appointments-list"></td>
<td>Modify Link</td>
<td>Add New Link</td>
<tr>';
};
$i++;
}//end while
}//end array fetch
echo '
</table>';
?>
Posted: Fri Jun 08, 2007 10:32 am
by ianhull
I have now modified this and used the cal_days_in_month instead of date 't'
Code: Select all
<link href="../styles/index.css" rel="stylesheet" type="text/css" />
<?php
echo '<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td class="calendar-numbers">Dates:</td>
<td class="appointments-list">Appointment Details:</td>
<td class="appointments-list">Modify</td>
<td class="appointments-list">Add New Appointment</td>
</tr>
<tr>';
$diary_dates = array();
if(isset($_GET['month'])){
$month = $_GET['month'];
} else {
$month = date('n');
};
if(isset($_GET['year'])){
$year = $_GET['year'];
} else {
$year = date('Y');
};
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/connection.php');
$getAppointments = mysql_query("SELECT
* FROM appointments WHERE appointment_month = '$month' AND appointment_year = '$year' AND assigned_to_firstname = '$firstname' AND assigned_to_surname = '$surname' ORDER BY appointment_day")or die(mysql_error());
while($appointmentsRecieved = mysql_fetch_array($getAppointments)){
$i = 1;
while($i <= cal_days_in_month(CAL_GREGORIAN, $month, $year)){
$time = mktime(0,0,0,$month, $i, $year);
$diary_dates[''.$i.''] = date('l jS', $time);
echo '<td class="calendar-numbers">'.$diary_dates[''.$i.''].'</td>';
if($appointmentsRecieved['appointment_day'] == $i){
echo '<td class="appointments-list">'.$appointmentsRecieved['company_name'].' '.$appointmentsRecieved['appointment_time'].' '.$appointmentsRecieved['city'].' '.$appointmentsRecieved['county'].' '.$appointmentsRecieved['postcode_1'].' '.$appointmentsRecieved['postcode_2'].'</td>
<td class="appointments-list">Modify Link</td>
<td class="appointments-list">Add New Link</td>
<tr>';
} else {
echo '<td class="appointments-list">s</td>
<td class="appointments-list">Modify Link</td>
<td class="appointments-list">Add New Link</td>
<tr>';
};
$i++;
}//end while
}//end array fetch
echo '
</table>';
?>
Still no luck.
If anyone can shine any light on my my table is not generated if there is no appointments listed it will be very much appreciated.
Thanks