Jump to content

[SOLVED] time diff in loop region


sheriff

Recommended Posts

hi all ...

I found a cool time diff script.

But i don't know how ca I use it in a loop region becouse I recive something like:

 

Fatal error: Cannot redeclare get_time_difference() (previously declared in C:\Program Files\xampp\htdocs\eurobild\final_evn.php:155)

 


<table border="0" cellpadding="1" cellspacing="1">


<tr>
	<td width="30px" bgcolor="#475558" align="center"><span class="c_text"><strong>ID</strong></span></td>
	<td width="100px" bgcolor="#475558" align="center"><span class="c_text"><strong>Subject</strong></span></td>
	<td width="100px" bgcolor="#475558" align="center"><span class="c_text"><strong>Componenta</strong></span></td>
	<td width="50px" bgcolor="#475558" align="center"><span class="c_text"><strong>Garantie</strong></span></td>
	<td width="50px" bgcolor="#475558" align="center"><span class="c_text"><strong>Preluat</strong></span></td>
	<td width="95px" bgcolor="#475558" align="center"><span class="c_text"><strong>Durata</strong></span></td></tr>

<?php

// EVENIMENTE PRELUATE

// Conexiunea la baza de date
include('include/constants.php');

// Afisarea mesajelor in funcite de msg_gar 
$query = "SELECT * FROM service WHERE solv_date is not NULL ORDER BY msg_date ASC";

$result = mysql_query($query);
$count = mysql_num_rows($result);

// Culoare alterata a randurilor
$color1 = "#FF9900"; 
$color2 = "#CCCCCC"; 
$row_count = 0; 

// Afiseaza continutul fiecarui rand in tabel
while( $row = mysql_fetch_array($result) ) {

$row_color = ($row_count % 2) ? $color1 : $color2;

$mid = $row['msg_id'];
$comp = $row['comp_id'];
$subject = $row['msg_name'];
$start = $row['msg_date'];
$msg = $row['msg_desc'];
$gar = $row['msg_gar'];
$end = $row['solv_date'];

?>
  
<tr>
	<td align="center" bgcolor="<?php echo $row_color; ?>"><font color="#000000" size="2"><?php echo $mid; ?></font></td>
	<td bgcolor="<?php echo $row_color; ?>"><font color="#000000" size="2">
	<a href="message.php?g=<?php echo $row[msg_gar];?>&id=<?php echo $row[comp_id]; ?>&msg_id=<?php echo $row[msg_id]; ?>" style="text-decoration: none;"> <?php echo $subject; ?></a></font></td>
	<td bgcolor="<?php echo $row_color; ?>" align="center"><font color="#000000" size="2"><?php echo $row[components]; ?></span></td>
	<td bgcolor="<?php echo $row_color; ?>" align="center"><font color="#000000" size="2"><?php echo $row[msg_gar]; ?></span></td>
	<td bgcolor="<?php echo $row_color; ?>" align="center"><font color="#000000" size="2"><?php echo $row[asigned_to]; ?></span></td>
	<td width="150px" bgcolor="<?php echo $row_color; ?>" align="center"><font color="#000000" size="2">

<?php
$query = "SELECT * FROM service WHERE solv_date is not NULL'";
$result = mysql_query($query);

// Afiseaza continutul fiecarui rand in tabel
while( $row = mysql_fetch_array($result) ) {

$start = $row[msg_date];
$end = $row[solv_date];

function get_time_difference( $start, $end )
{
    $uts['start']      =    strtotime( $start );
    $uts['end']        =    strtotime( $end );
    if( $uts['start']!==-1 && $uts['end']!==-1 )
    {
        if( $uts['end'] >= $uts['start'] )
        {
            $diff    =    $uts['end'] - $uts['start'];
            if( $days=intval((floor($diff/86400))) )
                $diff = $diff % 86400;
            if( $hours=intval((floor($diff/3600))) )
                $diff = $diff % 3600;
            if( $minutes=intval((floor($diff/60))) )
                $diff = $diff % 60;
            $diff    =    intval( $diff );            
            return( array('days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) );
        }
        else
        {
            trigger_error( "Ending date/time is earlier than the start date/time", E_USER_WARNING );
        }
    }
    else
    {
        trigger_error( "Invalid date/time data detected", E_USER_WARNING );
    }
    return( false );
}


// what is the time difference between $end and $start?
if( $diff=@get_time_difference($start, $end) )
{
  echo "Hours: " .
       sprintf( '%02d:%02d', $diff['hours'], $diff['minutes'] );
}
else
{
  echo "Hours: Error";
}
}
?>


	</font></td>
</tr>

<?php
} 
?>
</table>

 

Help me please :)

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/51289-solved-time-diff-in-loop-region/
Share on other sites

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.