TRI0N Posted March 17, 2008 Share Posted March 17, 2008 Well don't look like I can run these functions more then once to get what I want for each results. Any help to make this happen with the same results would be great. Right now it will give me results 28 day, 16 hrs. or 5 hrs, 47 sec. when down that close. Right now when I run this I get an error that it cannot run the function more then once. Bogus because this Date Difference script is quite nice. // Database Connection mysql_connect("$dbhost","$dbuser","$dbpasswd") ; // Database Selection mysql_select_db("$dbname") ; $result3 = mysql_query("select * from events WHERE inquiry = 1") ; while($row = mysql_fetch_row($result3)) { $event_id = $row[1] ; $client_id = $row[2] ; $response_date = $row[40] ; $response_time = $row[41] ; $proposal_date = $row[42] ; $proposal_time = $row[43] ; $rtr = '' ; $rtr2 = '' ; $ptr = '' ; $ptr2 = '' ; if($response_date != '0000-00-00') { $response = explode('-', $row[40]) ; $response_yr = $response[0] ; $response_mo = $response[1] ; $response_dy = $response[2] ; if($response_mo == 1) { $d_mo = 'Jan' ; } if($response_mo == 2) { $d_mo = 'Feb' ; } if($response_mo == 3) { $d_mo = 'Mar' ; } if($response_mo == 4) { $d_mo = 'Apr' ; } if($response_mo == 5) { $d_mo = 'May' ; } if($response_mo == 6) { $d_mo = 'Jun' ; } if($response_mo == 7) { $d_mo = 'Jul' ; } if($response_mo == { $d_mo = 'Aug' ; } if($response_mo == 9) { $d_mo = 'Sep' ; } if($response_mo == 10) { $d_mo = 'Oct' ; } if($response_mo == 11) { $d_mo = 'Nov' ; } if($response_mo == 12) { $d_mo = 'Dec' ; } $rtr = $d_mo.' '.$response_dy.', '.$response_yr.' '.$response_time ; $rtr2 = date("M j, Y H:i:s") ; $t1 = $rtr ; $t2 = $rtr2 ; function date_diff ($t1, $t2, $precision = 6, $abbr = false) { if (preg_match('/\D/', $t1) && ($t1 = strtotime($t1)) === false) return false; if (preg_match('/\D/', $t2) && ($t2 = strtotime($t2)) === false) return false; if ($t1 > $t2) list($t1, $t2) = array($t2, $t1); $diffs = array( 'year' => 0, 'month' => 0, 'day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0, ); $abbrs = array( 'year' => 'yr', 'month' => 'mth', 'day' => 'day', 'hour' => 'hr', 'minute' => 'min', 'second' => 'sec' ); foreach (array_keys($diffs) as $interval) { while ($t2 >= ($t3 = strtotime("+1 ${interval}", $t1))) { $t1 = $t3; ++$diffs[$interval]; } } $stack = array(); foreach ($diffs as $interval => $num) $stack[] = array($num, ($abbr ? $abbrs[$interval] : $interval) . ($num != 1 ? 's' : '')); $ret = array(); while (count($ret) < $precision && ($item = array_shift($stack)) !== null) { if ($item[0] > 0) $ret[] = "{$item[0]} {$item[1]}"; } return implode(', ', $ret); } $rtr = date_diff($t1, $t2, 2, true) ; } if($proposal_date != '0000-00-00') { $proposal = explode('-', $row[42]) ; $proposal_yr = $proposal[0] ; $proposal_mo = $proposal[1] ; $proposal_dy = $proposal[2] ; if($proposal_mo == 1) { $d_mo = 'Jan' ; } if($proposal_mo == 2) { $d_mo = 'Feb' ; } if($proposal_mo == 3) { $d_mo = 'Mar' ; } if($proposal_mo == 4) { $d_mo = 'Apr' ; } if($proposal_mo == 5) { $d_mo = 'May' ; } if($proposal_mo == 6) { $d_mo = 'Jun' ; } if($proposal_mo == 7) { $d_mo = 'Jul' ; } if($proposal_mo == { $d_mo = 'Aug' ; } if($proposal_mo == 9) { $d_mo = 'Sep' ; } if($proposal_mo == 10) { $d_mo = 'Oct' ; } if($proposal_mo == 11) { $d_mo = 'Nov' ; } if($proposal_mo == 12) { $d_mo = 'Dec' ; } $ptr = $d_mo.' '.$proposal_dy.', '.$proposal_yr.' '.$proposal_time ; $ptr2 = date("M j, Y H:i:s") ; $t4 = $ptr ; $t5 = $ptr2 ; function pro_diff ($t4, $t5, $precision = 6, $abbr = false) { if (preg_match('/\D/', $t4) && ($t4 = strtotime($t4)) === false) return false ; if (preg_match('/\D/', $t5) && ($t5 = strtotime($t5)) === false) return false ; if ($t4 > $t5) list($t4, $t5) = array($t5, $t4) ; $diffs = array( 'year' => 0, 'month' => 0, 'day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0, ) ; $abbrs = array( 'year' => 'yr', 'month' => 'mth', 'day' => 'day', 'hour' => 'hr', 'minute' => 'min', 'second' => 'sec' ) ; foreach (array_keys($diffs) as $interval) { while ($t5 >= ($t6 = strtotime("+1 ${interval}", $t4))) { $t4 = $t6 ; ++$diffs[$interval] ; } } $stack = array(); foreach ($diffs as $interval => $num) $stack[] = array($num, ($abbr ? $abbrs[$interval] : $interval) . ($num != 1 ? 's' : '')) ; $ret = array(); while (count($ret) < $precision && ($item = array_shift($stack)) !== null) { if ($item[0] > 0) $ret[] = "{$item[0]} {$item[1]}" ; } return implode(', ', $ret) ; } $ptr = pro_diff($t4, $t5, 2, true) ; } $result4 = mysql_query("select distinct * from clients WHERE client_id = '$client_id' ORDER BY l_name ASC") ; while($row = mysql_fetch_row($result4)) { $client_id = $row[1] ; $client_name = $row[2].', '.$row[3] ; echo '<tr>' ; echo '<td><p align="left"><a href="inq-new.php?action=client_update&client_id='.$client_id.'&event_update=1&event_id='.$event_id.'">'.$client_name.'</a></p></td>' ; echo '<td><p align="center">'.$response_date.'</p></td>' ; echo '<td><p align="center">'.$rtr.'</p></td>' ; echo '<td><p align="center">'.$proposal_date.'</p></td>' ; echo '<td><p align="center">'.$ptr.'</p></td>' ; echo '<td><p align="center"> </p></td>' ; echo '<td><p align="center"> </p></td>' ; echo '</tr>' ; } } // Close Database Connection mysql_close(); Thanks again for any help on this.. Quote Link to comment https://forums.phpfreaks.com/topic/96497-solution-to-a-function-error/ Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 what does it do is all that a simple mysql query but put in php syntex........ Quote Link to comment https://forums.phpfreaks.com/topic/96497-solution-to-a-function-error/#findComment-493853 Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 There is no function defined in your code, what is the exact error you are getting? Quote Link to comment https://forums.phpfreaks.com/topic/96497-solution-to-a-function-error/#findComment-493863 Share on other sites More sharing options...
sasa Posted March 17, 2008 Share Posted March 17, 2008 move function definition(lines 70 - 108 and 161 - 199) before 1st while loop Quote Link to comment https://forums.phpfreaks.com/topic/96497-solution-to-a-function-error/#findComment-493875 Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 There is no function defined in your code, what is the exact error you are getting? Hehe, I suppose it helps to scroll down hey? Quote Link to comment https://forums.phpfreaks.com/topic/96497-solution-to-a-function-error/#findComment-493913 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.