hey jim thanks for the reply so i got that working but now i am having issues calculating time left until we reach the expired time…
the values:
created = 1391876271
length = 1
my code:
[php]
.row0 {
background-color: #666;
}
tr.row0:hover {
background-color: #ccc;
}
.row1 {
background-color: #333;
}
tr.row1:hover {
background-color: #ddd;
}
<?php
date_default_timezone_set ('America/New_York');
$rowclass = 0;
function conv2sec($seconds)
{
$y = floor($seconds / (86400*365.25));
$d = floor(($seconds - ($y*(86400*365.25))) / 86400);
$h = gmdate('H', $seconds);
$m = gmdate('i', $seconds);
$s = gmdate('s', $seconds);
$string = '';
if($y > 0)
{
$yw = $y > 1 ? ' Years ' : ' Year ';
$string .= $y . $yw;
}
if($d > 0)
{
$dw = $d > 1 ? ' Days ' : ' Day ';
$string .= $d . $dw;
}
if($h > 0)
{
$hw = $h > 1 ? ' Hrs ' : ' Hr ';
$string .= $h . $hw;
}
if($m > 0)
{
$mw = $m > 1 ? ' Mins ' : ' Min ';
$string .= $m . $mw;
}
if($s > 0)
{
$sw = $s > 1 ? ' Secs ' : ' Sec ';
$string .= $s . $sw;
}
return preg_replace('/\s+/',' ',$string);
}
$con=mysqli_connect(“xxxx”,“xxxx”,“xxxx”,“xxxxx”);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,“SELECT * FROM table”);
?>
Name |
ID |
Reason |
Expires |
By |
When |
Time Left |
<?php
while($row = mysqli_fetch_array($result))
{
$rowclass = 1 - $rowclass;
$created = $row['created']; //date created as timestamp (seconds)
$length = $row['length']*60; //input is mins so we need to *60 to get seconds
$ends = $created+$length; //calc expire date as timestamp (seconds)
$diff = time()-$ends; //calc diff from now till expire
$res = conv2sec($diff); //format seconds of diff to time output
?>
<?php echo $row['name']; ?> |
<?php echo $row['id']; ?> |
<?php echo $row['reason']; ?> |
<?php echo date("m/d/Y g:ia", $ends); ?> |
<?php echo $row['by']; ?> |
<?php echo date("m/d/Y g:ia", $created); ?> |
<?php echo $res; ?> |
<?php
}
?>
<?php
mysqli_close($con);
?>
[/php]
Displays: 01 hr 20 mins 05 secs
expected result: 59 secs
the 1 in length is in minutes and its reading anything under 60 as hours if i change length to 60 i get a display of
01 hr 23 mins 15 secs
and now it reads the 60 as mins …
i am confuzzeled!!! :’( :’( :’(