473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Retrieving and comparing data from arrays

41
Hi

I am php newbie and I don't know if I am approaching this properly.
I need to creat a scheduler that list the appointment time on the left
and client for a specific appointment time on the left.

NOTE: The appointments are stored in a Mysql database

This is what I am trying to acomplish:

Time | client Name
-------------------------------------------
09:00 AM |
10:00 AM | John Smith
11:00 AM |
to
09:00 PM | Mike Smith



The problem I am having is getting the appointments on the
right to match up with the time on the left.


This is what I am getting with the code below:


Time | client Name
------------------------------------------------
09:00 AM | John Smith
10:00 AM | Mike Smith
11:00 AM |
to
09:00 PM |



[php]
<?
/**--------------------------time interval--------------------**/
//array with time interval listing found on the left side of the page
$time_60min_array = array(
'06:00 AM', '07:00 AM', '08:00 AM', '09:00 AM', '10:00 AM', '11:00 AM',
'12:00 PM', '01:00 PM', '02:00 PM', '03:00 PM', '04:00 PM', '05:00 PM',
'06:00 PM', '07:00 PM', '08:00 PM', '09:00 PM');

/**-------------select appointment from database-----------------**/
// select by date to match to time interval listing
$query = "SELECT distinct(event_id), event_date, event_time, event_am_pm,
first_name, last_name,
FROM cal_appointment
WHERE event_date = '$event_date'
ORDER BY event_date, event_am_pm, event_time";

$result = mysqli_query($mysqli, $query) or die('Error, query failed');

/**-------------------------------title--------------------------**/
echo "<div id=\"Layer4\" style=\"position:absolute; margin: 4px; width:100%; height:20px; z-index:4; left: 4px; top: 430px;\">\n";
echo "<table width=\"98.5%\" margin=\"\" left =\"4\" align=\"center\">
<tr>
<td width=\"30%\" height=\"12\" align=\"center\"
bgcolor=\"#eeeee0 \"> <span class=\"style20\"> <strong>Time</strong></span></td>
<td width=\"68%\" height=\"12\" align=\"center\" bgcolor=\"#eeeee0\"><span class=\"style20\"><strong>Patient</strong></span></td>
</tr>\n";
echo "</table>\n";
echo "</div>\n";

//search area display area layer and table
echo "<table width=\"99%\" border=\"0\">
<tr align=\"center\" bgcolor=\"#FFFFFF\" height=\"\">
<td width=\"100%\" >
<div id=\"Layer2\" style=\"position:absolute; width:100%; height:500px;
z-index:2; left: 4px; top: 465px;\">
<div id=\"scroll-box2\" style=\"overflow: auto; float: left; width: 100%;
height: 480px; margin: 5px; \">\n";


//table begins
echo "<table width=\"100%\" height=\"332\" left =\"4\" align = \"\" border=\"0\" font face =\"arial\">\n";


/**--------------------------display------------------------**/
$result = mysqli_query($mysqli, $query) or die('Error, query failed');

for($i=0; $i < count($time_60min_array ); $i++)
{
$row = mysqli_fetch_array($result);

list($event_id, $event_date, $event_time, $event_am_pm,$first, $last) = $row;


//format time
$appoint_time = $hour.":".$minutes." ".$am_pm;

//match appointment time on right to time listing on left
if(in_array($appoint_time, $time_60min_array))
{
$s_event_id = $event_id;
$client_name = $last.", ".$first;
}

//display list
echo"<tr height=\"10\">
<td width=30% height=\"10\" bgcolor=\"$bgcolor\"
align=\"center\">$time_interval[$i]</td>
<td width=\"70%\" height=\"10\" bgcolor=\"$bgcolor\"><span
class=\"style20\">$client_name</td>\n";
echo"</tr>\n";
}
?>
[/php]
Jun 28 '07 #1
4 1519
assgar
41
I forgot to add the end of the table structure

[php]
<?
echo"</div>\n";
echo "</div>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</table>\n";
?>
[/php]
Jun 28 '07 #2
pbmods
5,821 Expert 4TB
Heya, assgar.
I forgot to add the end of the table structure
I think it's safe to say that that part is not the problem ~_^

[EDIT: Also not directly related, but you might be interested. DISTINCT is not a function in MySQL. So the parenthesis in your query aren't actually doing anything.

Your query gets evaluated like this (note GROUP BY clause):

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT event_id, event_date, event_time, event_am_pm, first_name, last_name FROM cal_appointment WHERE event_date = '$event_date' GROUP BY event_id, event_date, event_time, event_am_pm, first_name, last_name ORDER BY event_date, event_am_pm, event_time
]
Jun 29 '07 #3
assgar
41
Heya, assgar.


I think it's safe to say that that part is not the problem ~_^

[EDIT: Also not directly related, but you might be interested. DISTINCT is not a function in MySQL. So the parenthesis in your query aren't actually doing anything.

Your query gets evaluated like this (note GROUP BY clause):

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT event_id, event_date, event_time, event_am_pm, first_name, last_name FROM cal_appointment WHERE event_date = '$event_date' GROUP BY event_id, event_date, event_time, event_am_pm, first_name, last_name ORDER BY event_date, event_am_pm, event_time
]

Thanks for the info on the select statement I changed it. This though is not a solution to matching the schedule time eg 07:00 AM to the client name with an appointment for 07:00AM.
Jun 29 '07 #4
assgar
41
Hello
Thanks for the info its was the best way to make this work.

This is the solution, this final code allows you to double book appointments.


[php]
<?

/**---------------------------appointment interval--------------------------**/
SWITCH($time_interval)
{
case 10:
$add_time = 600; //10 min appointment
break;

case 15:
$add_time = 900; //15 min appointment
break;

case 20:
$add_time = 1200; //20 min appointment
break;

case 30:
$add_time = 1800; //30 min appointment
break;

case 60:
$add_time = 3600; //60 min appointment
break;

default:
$add_time = 900; //15 min appointment
break;
}
/**-------------------------------search by date-----------------------------------**/
$query = "SELECT event_id, event_date, event_time,
first_name, last_name
FROM cal_appointment
WHERE a.event_date = '$event'
GROUP BY a.event_id, a.event_date, a.event_time,
first_name, last_name
ORDER BY event_time, last_name, first_name
";

$result = mysqli_query($mysqli, $query) or die('Error, query failed');


/************************** this section displays events********************************/

/**-Note: <table> tags etc. go here**/

//declare array
$events = array();

//Storing the rows rather than outputting them immediately
while($row = mysqli_fetch_array($result))
{
$events[] = $row;
}

//Loop over the hours from 9AM to 6PM
for ($time = $start_time; $time <= $end_time; $time += $add_time)
{
//format 24 hour time interval for passing via url
$interval_24hr = date("H:i:s", $time);


echo "<tr>";
//Output the time interval label
echo"<td width=\"10%\" height=\"15\" bgcolor=\"#e6e8fa\" align=\"center\">".date("h:i A", $time)."</td>";


//start of next cell
foreach ($events as $event)
{
list($event_hr,$event_min,$event_sec) = split(":",$event['event_time']);

//convert event time for comparison
$event_time = mktime($event_hr, $event_min, $event_sec);

//Event falls into this hour
if($event_time >= $time && $event_time < ($time + $add_time))
{
//format client name
$client_name = $event['last_name'].", ".$event['first_name'];

//looping data diaplayed
echo "<td width=\"20%\" height=\"10\" bgcolor=\"$bgcolor\"><span class=\"style20\"><div style = \"margin-left:10;\">$client_name</td>";
}//end if

}//end foreach

echo "</tr>";
}//end for

/**Note: end of </table> etc. goes here**/
}
?>
[/php]
Jul 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Dan Stromberg | last post by:
We will soon have 3 copies, for testing purposes, of what should be about 4.5 terrabytes of data. Rather than cmp'ing twice, to verify data integrity, I was thinking we could speed up the...
11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
1
by: Iain | last post by:
Hi Hopefully I am missing something really simple with this question, but here goes. I have two Bitarrays that I would like to compare. At the moment, I am XORing one with the other and...
12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
6
by: Taxi Driver | last post by:
Hi Everyone - Can I get your help with this, it is driving me crazy. I have 2 arrays listed below: @req=75 @req=76 @req=77 @req=78 --- @bid=75 @bid=76
18
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When...
1
by: Donald Grove | last post by:
If I have two arrays, what is a good paradigm for comparing what is in them, to determine what elements they share, or don't share? Specifically, each array could potentially contain the integers...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
1
by: psmahesh | last post by:
Hi folks, I am comparing two arrays and removing matches from the second array from the first array. Can someone take a look at this code below and mention if this is okay and perhaps if there...
3
by: Sean Dalton | last post by:
Hello, I have a two sets OLDLIST and REMOVE. I would like to remove every element in OLDLIST if it is also occuring in REMOVE and store the remaining elements from OLDLIST into NEWLIST. So...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.