just me and php Posted February 8, 2007 Share Posted February 8, 2007 from a table in my database i get a set of numbers like this 1. 10:06.52 2. 10:06.93 3. 10:10.54 4. 11:18.65 5. 7:52.39 6. 8:01.51 7. 8:37.37 8. 8:41.01 9. 8:43.79 10. 9:05.03 11. 9:17.96 12. 9:19.29 13. 9:23.45 14. 9:25.03 15. 9:25.78 16. 9:33.70 but i would like it to be this 1. 07:52.39 2. 08:01.51 3. 08:37.37 4. 08:41.01 5. 08:43.79 6. 09:05.03 7. 09:17.96 8. 09:19.29 9. 09:23.45 10. 09:25.03 11. 09:25.78 12. 09:33.70 13. 10:06.52 14. 10:06.93 15. 10:10.54 16. 11:18.65 is there a way i could add an if (statement) or something in my sqlquery ??to add a 0 in front of all numbers below 10:00.00 Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted February 8, 2007 Share Posted February 8, 2007 yes you can use functions like strpos strlen http://www.phpbuilder.com/manual/en/function.strlen.php Quote Link to comment Share on other sites More sharing options...
just me and php Posted February 8, 2007 Author Share Posted February 8, 2007 hmm that example i dont understand how it could be used to add a 0 in front of numbers below 10:00.00 like 09:99.99 <?php $str = 'abcdef'; echo strlen($str); // 6 $str = ' ab cd '; echo strlen($str); // 7 ?> Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted February 8, 2007 Share Posted February 8, 2007 <?php $str ="0.1.1"; if (strlen($str) ==5) { echo "0$str";} // 6 ?> Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 8, 2007 Share Posted February 8, 2007 if (strlen($str) == 7) {$str = '0'.$str;} or something like that. Quote Link to comment Share on other sites More sharing options...
just me and php Posted February 8, 2007 Author Share Posted February 8, 2007 PERFECT Thanks offsprg01 That Works Great Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 8, 2007 Share Posted February 8, 2007 Try this: <?php function zerofill($str) { list($part1,$part2) = explode(':',$str); return(sprintf("%02d:%s",$part1,$part2)); } $temp = array(); $teststrs = array('7:52.39','10:10.54','11:18.65','8:01.51','8:37.37','8:41.01','9:43.79'); foreach($teststrs as $test) $temp[] = zerofill($test); sort($temp); echo '<pre>' . print_r($temp,true) . '<pre>'; ?> Ken Quote Link to comment 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.