Hi Sridhar,
I have been working with the code you gave me almost all night and still cant get it working! Am i putting code in the wrong places??? Where should i incorporate this code? Take a look at my codes...
//Output-view code
<body>
<center>
<h1>Student Timesheet</h1>
<?
// For each of the times (once you get it to the 00:00 format), use the explode function to split it into an array of hour and minute.
// Then add them together:
$tarray = explode(":", $timeIn_one);
$tone_in = ($tarray[0]60) + $tarray[1];
$tarray = explode(":", $timeOut_one);
$tone_out = ($tarray[0]60) + $tarray[1];
// Subtract $tone_in from $tone_out:
$total_timeOne = $tone_out - $tone_in;
// So now $total_timeOne is in Minutes.
// Do the same from timeTwo.
$tarray = explode(":", $timeIn_two);
$ttwo_in = ($tarray[0]60) + $tarray[1];
$tarray = explode(":", $timeOut_two);
$ttwo_out = ($tarray[0]60) + $tarray[1];
// Subtract $ttwo_in from $ttwo_out:
$total_timeTwo = $ttwo_out - $ttwo_in;
// Add them together. Now you'll ask: How do I convert this to 00:00?
$totaltime = $total_timeOne + $total_timeTwo;
// Easy...
// assume $totaltime is the total time in minutes:
$hours = floor($totaltime/60);
$minutes = $totaltime%60;
$formatted_time = "$hours:$minutes";
$sql = "SELECT * from st";
If ($date)
$sql .= "name like '%$date%' and ";
If ($timeIn_one)
$sql .= "email like '%$timeIn_one%' and ";
If ($timeOut_one)
$sql .= "password like '%$timeOut_one%' and ";
If ($timeIn_two)
$sql .= "department like '%$timeIn_two%' and ";
If ($timeOut_two)
$sql .= "department like '%$timeOut_two%' and ";
If ($tot_hrs_day)
$sql .= "department like '%$tot_hrs_day%' and ";
$connection = mysql_connect("localhost","univrel","univrel") or die ("Couldn't connect to server.");
$db = mysql_select_db("univrel",$connection) or die ("Couldn't connect to database.");
$sql_result = mysql_query($sql,$connection);
?>
<table border=\"1\" cellspacing=\"5\" cellpadding=\"3\" width=\"50%\">
<tr>
<td align="center"><b>Date</b></td>
<td align="center"><b>Time In:</b></td>
<td align="center"><b>Time Out:</b></td>
<td align="center"><b>Time In:</b></td>
<td align="center"><b>Time Out:</b></td>
<td align="center"><b>Total Time of Day</b></td>
</tr>
<?
while (($row = mysql_fetch_object($sql_result)))
{
printf("<tr>
<td><center>%s</center></td>
<td><center>%s</center></td>
<td><center>%s</center></td>
<td><center>%s</center></td>
<td><center>%s</center></td>
<td><center>$formatted_time </center></td>
<td><a href=\"dummylogin.php3?rowid=%s\"><I>Log time</I></a></td>
</tr>\n", $row->date,
substr($row->timeIn_one,0,strlen($row->timeIn_one)-3),
substr($row->timeOut_one,0,strlen($row->timeOut_one)-3),
substr($row->timeIn_two,0,strlen($row->timeIn_two)-3),
substr($row->timeOut_two,0,strlen($row->timeOut_two)-3),
substr($row->formatted_time,0,strlen($row->formatted_time)-3),
$row->rowid);
}
printf("</table>\n");
mysql_free_result($sql_result);
?>
</form>
</center>
</body>
// Log time page
<body>
<center>
<form action="dummyupdate.php3" method="post">
<b><h1>Log time for the day</h1></b>
<?
$sql = "select * from st where rowid=$rowid";
$connection = mysql_connect("localhost","univrel","univrel") or die ("Couldn't connect to server.");
$db = mysql_select_db("univrel",$connection) or die ("Couldn't connect to database.");
$result = mysql_query($sql, $connection);
$row = mysql_fetch_object($result);
$resultentry["timeIn_one"] = substr($row->timeIn_one,0,strlen($row->timeIn_one)-3);
$resultentry["timeOut_one"] = substr($row->timeOut_one,0,strlen($row->timeOut_one)-3);
$resultentry["timeIn_two"] = substr($row->timeIn_two,0,strlen($row->timeIn_two)-3);
$resultentry["timeOut_two"] = substr($row->timeOut_two,0,strlen($row->timeOut_two)-3);
printf("<input type=hidden name=rowid value='%s'>", $rowid);
printf("Time In:<br>
<input type=time name=timeIn_one value='%s'><br><br>
", $resultentry["timeIn_one"]);
printf("Time Out:<br>
<input type=time name=timeOut_one value='%s'><br><br>
", $resultentry["timeOut_one"]);
printf("Time In:<br>
<input type=time name=timeIn_two value='%s'><br><br>
", $resultentry["timeIn_two"]);
printf("Time Out:<br>
<input type=time name=timeOut_two value='%s'><br><br>
", $resultentry["timeOut_two"]);
printf("<input type=Submit value=Update time>");
printf("</form");
mysql_free_result($result);
?>
<br>
<br><br>
<a href="dummyview.php3">Cancel</a>
</form>
</center>
</body>
// Update timesheet page
<?
$update = "Update st set timeIn_one='${timeIn_one}:00', timeOut_one='${timeOut_one}:00', timeIn_two='${timeIn_two}:00', timeOut_two='${timeOut_two}:00', formatted_time='${formatted_time}:00' where rowid=$rowid";
$connection = mysql_connect("localhost","univrel","univrel") or die ("Couldn't connect to server.");
$db = mysql_select_db("univrel",$connection) or die ("Couldn't connect to database.");
$sql_result = mysql_query($update, $connection);
header ("location: dummyview.php3");
?>
Whatcha think?