Hello!
I’m running some PHP code that does what I want, but it’s insanely slow and I’m not sure if there’s anything that can be done about it. If you go to:
Create Algebra Assignment and enter a date, and Create Class Schedule, the routine will run. I call the following functions, located in an external file:
function convertLocalTimetoUnixTimestamp ($local_time_zone,$formatted_time) {
// create the DateTimeZone object for later
$dtzone = new DateTimeZone($local_time_zone);
// now create the DateTime object for this time and user time zone
$dtime = new DateTime($formatted_time, $dtzone);
// print the timestamp
$timestamp = $dtime->format('U');
return $timestamp;
}
function convertUnixTimestamptoLocalTime ($local_time_zone,$unix_time,$time_format) {
// create the DateTimeZone object for later
$dtzone = new DateTimeZone($local_time_zone);
// first convert the timestamp into a string representing the local time
$time = date('r', $unix_time);
// now create the DateTime object for this time
$dtime = new DateTime($time);
// convert this to the user's timezone using the DateTimeZone object
$dtime->setTimeZone($dtzone);
// print the time using your preferred format
// print the time using your preferred format
$local_time_formatted = $dtime->format($time_format);
return $local_time_formatted;
}
function getDueHomePageHomeSchoolAssignments($read,$user_id) {
$sql = "SELECT homepage_homeschool_schedule.assignment_id, homepage_homeschool_schedule.assignment_start_date, homepage_homeschool_schedule.time_zone, homepage_homeschool_schedule.assignment_due_date, assignments_instructors.assignment_name
FROM homepage_homeschool_schedule
INNER JOIN
assignments_instructors
WHERE assignments_instructors.assignment_id = homepage_homeschool_schedule.assignment_id
AND user_id = $user_id
ORDER BY assignment_due_date ASC";
return $read->fetchAll($sql);
}
function getAssignmentTopics($read,$assignment_id) {
$sql = "SELECT distinct(section_page_title), book_order, assignments_topics.section_name, assignments_topics.chapter_name
FROM assignments_topics
INNER JOIN questions
ON assignments_topics.section_name=questions.section_name
WHERE questions.question_id
IN
(SELECT question_id
FROM assignments_questions
WHERE assignment_id=$assignment_id)
ORDER BY (book_order);";
return $read->fetchAll($sql);
}
The actual code to run the process is:
<table id="users_table">
<?php $due_assignments = getDueHomePageHomeSchoolAssignments($dbRead,$user_id);
if ($due_assignments) { ?>
<tr>
<th>Assignment</th>
<th>Topics</th>
<th>Start Date</th>
<th>Due Date</th>
</tr> <?php ;} ?>
<?php foreach($due_assignments as $row) { //repeat region
$assignment_topics = getAssignmentTopics($dbRead,$row['assignment_id']);
?>
<tr>
<td><?php echo $row['assignment_name'] ?></td>
<td>
<?php foreach($assignment_topics as $assignment_topic){
echo $assignment_topic['section_page_title']."<br />";}?></td>
<td>
<?php
echo convertUnixTimestamptoLocalTime ($row['time_zone'],$row['assignment_start_date'],"m/j/y") . " at " . convertUnixTimestamptoLocalTime ($row['time_zone'],$row['assignment_start_date'],"g:i a");
?></td>
<td><?php
echo convertUnixTimestamptoLocalTime ($row['time_zone'],$row['assignment_due_date'],"m/j/y") . " at " . convertUnixTimestamptoLocalTime ($row['time_zone'],$row['assignment_due_date'],"g:i a");
?>
</td>
</tr>
<?php } // end of repeat region ?>
</table>
Are there any thoughts as to why it should take upwards of 45 seconds for the full menu to print out would be appreciated (I have Comcast, by the way).
Thank you…
-Eric