Jump to content

counting numbers (time/clock related)


synstealth

Recommended Posts

I seem to have trouble counting the time pulled from database.. for example

 

one record has 5 rows of clocked in times  when pulled. it looks like this...

 

0:30

0:30

1:30

1:15

0:45

 

now I want to sum it all up and output the total time elapsed.  I cant seem to stop the script from counting past "60"  it just increments like a standard number.. I am little confused using the maketime() function.  anyone glad to help ??

 

I just need to "see" the script to understand how to count the times so I can play around with it.

 

(on my project I am making an progress bar that will output how much time is left - records pulled from db with users that has input # of hours they worked on a task. )

 

 

this is my example snippet using get_num() to gather the user's hours they clocked in.

 

function get_num($tbl,$value){
connect();
$total = mysql_num_rows(sql("SELECT * FROM $tbl")) or 
die('
	<br /><center>
	<table border="1" bordercolor="red" cellpadding="0" cellspacing="0" width="450" height="100">
	<tr>
		<td align="center"><b>There are no task to graph</b></td>
	</tr>
	</table>
	</center><br />
');
$result = mysql_num_rows(sql("SELECT * FROM $tbl WHERE agenda_resource_id='$value'"));
$res_bar='';
$num = 5 - $result; // maximum 5 hours they are allowed to work // calculates the remain time

for($bar=0; $bar<$result; $bar++){

	$res_bar .= '<td bgcolor="orange" align="left">0</td>';

}	
for($b=1; $b<$num; $b++){

	$res_bar .= '<td bgcolor="yellow" align="left">y</td>';

}

$res_bar .='<td bgcolor="yellow">'.$clock.' Hours Remaining</td>';

// undefined variable - $clock is the calculated time they have left



return $res_bar;
}

 

it outputs as orange background indicates the time used.

yellow background is  the  "progress bar" to show how much time is left with the value ($clock)

 

hope I am clear..

 

Link to comment
https://forums.phpfreaks.com/topic/93111-counting-numbers-timeclock-related/
Share on other sites

I didnt realize I posted the old code..

 

here's the updated one. hope this is clear to understand what Im trying to do.

 

function get_num($tbl,$value){
connect();
$total = mysql_num_rows(sql("SELECT * FROM $tbl")) or 
die('
	<br /><center>
	<table border="1" bordercolor="red" cellpadding="0" cellspacing="0" width="450" height="100">
	<tr>
		<td align="center"><b>There are no task to graph</b></td>
	</tr>
	</table>
	</center><br />
');
$query = sql("SELECT * FROM $tbl WHERE agenda_resource_id='$value'");
while($t = mysql_fetch_array($query)){

	$fix = explode(":",$t['etw']);

	$h = $fix[0];
	$m = $fix[1];

	$h =+ $h;


	$m =+ $m; // how do I count the times without going past 60....

	$clock = $h.':'.$m;
}

$result = mysql_num_rows(sql("SELECT * FROM $tbl WHERE agenda_resource_id='$value'"));
$res_bar='';
$num = 5 - $result;

for($bar=0; $bar<$result; $bar++){


	$res_bar .= '<td bgcolor="orange" align="left">0</td>';

}	
for($b=1; $b<$num; $b++){

	$res_bar .= '<td bgcolor="yellow" align="left">y</td>';

}
$res_bar .='<td bgcolor="yellow">'.$clock.' Hours Remaining</td>';
$output = $res_bar;



return $output;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.