dniwebdesign
03-07-2005, 07:11 AM
I have a online timesheet thing for my employees. I want to take the hours they've worked from the DB form each row and add them together, for each client. Each clients timesheet is stored in the same DB. I had the below but it times out, so I think I might be doing something wrong.
<?php
$sql = mysql_query("SELECT * FROM dnidesign_employee_profile WHERE account='".$_SESSION["account"]."'",$connection) or print mysql_error();
$login_check = mysql_num_rows($sql);
if($login_check > 0)
{
while($row = mysql_fetch_array($sql))
{
foreach( $row AS $key => $val )
{
$$key = stripslashes( $val );
}
$result1 = mysql_query("SELECT * FROM dnidesign_employee_timesheets WHERE employee='".$_SESSION["account"]."'",$connection) or print mysql_error();
$total_hours=mysql_num_rows($result1);
for($i=0; $i<$total_hours; $i++)
{
$result2 = mysql_query("SELECT hourformat FROM dnidesign_employee_timesheets WHERE employee='".$_SESSION["account"]."'",$connection) or print mysql_error();
if(mysql_num_rows($result2) >= 1)
{
while($rower=mysql_fetch_array($result2))
{
$total_hours += $rower["hourformat"];
}
}
}
?>
<?php
$sql = mysql_query("SELECT * FROM dnidesign_employee_profile WHERE account='".$_SESSION["account"]."'",$connection) or print mysql_error();
$login_check = mysql_num_rows($sql);
if($login_check > 0)
{
while($row = mysql_fetch_array($sql))
{
foreach( $row AS $key => $val )
{
$$key = stripslashes( $val );
}
$result1 = mysql_query("SELECT * FROM dnidesign_employee_timesheets WHERE employee='".$_SESSION["account"]."'",$connection) or print mysql_error();
$total_hours=mysql_num_rows($result1);
for($i=0; $i<$total_hours; $i++)
{
$result2 = mysql_query("SELECT hourformat FROM dnidesign_employee_timesheets WHERE employee='".$_SESSION["account"]."'",$connection) or print mysql_error();
if(mysql_num_rows($result2) >= 1)
{
while($rower=mysql_fetch_array($result2))
{
$total_hours += $rower["hourformat"];
}
}
}
?>