I am writing a script in PHP that will convert time and I am having trouble updating the database again once the
calculations are done.
Could someone have a look at the script and see if I am headed in the right direction??
Please see below for more details.
<?php
# Connect to MySQL
$link = mysql_connect($hostname, $username, $password)
or die("Could not connect to database<br>\n");
# Select correct database within MySQL and select time fields needed
mysql_select_db("charman_timesheets", $link)
or die("Could not select the correct database");
$start_time = mysql_query("select start_time from charman_timesheets");
$stop_time = mysql_query("select stop_time from charman_timesheets");
# Split times needed into minutes to create total time
function start_time_calc($start_time)
{
if (strstr($start_time, ':'))
{
# Split hours and minutes.
$separatedData1 = split(':', $start_time);
$minutesInHours1 = $separatedData1[0] * 60;
$minutesInDecimals1 = $separatedData1[1];
$totalMinutes1 = $minutesInHours1 + $minutesInDecimals1;
}
else
{
$totalMinutes1 = $start_time * 60;
}
return $totalMinutes1;
}
function stop_time_calc($stop_time)
{
if (strstr($stop_time, ':'))
{
# Split hours and minutes.
$separatedData2 = split(':', $stop_time);
$minutesInHours2 = $separatedData2[0] * 60;
$minutesInDecimals2 = $separatedData2[1];
$totalMinutes2 = $minutesInHours2 + $minutesInDecimals2;
}
else
{
$totalMinutes2 = $stoptime * 60;
}
return $totalMinutes2;
}
$total_time = $totalMinutes2 - $totalMinutes1
$total_time2 = $total_time / 60
$query = "UPDATE charman_timesheets SET total_time='$totaltime2' WHERE (total_time='00:00')";
$result = mysql_query($query2);
?>