budimir Posted May 23, 2008 Share Posted May 23, 2008 Hey guys, I need some help with the export to CSV. I need to export only some fields from the DB to CSV. Some of those fields I need to limit to 35 chaaracters, change number format from 1,234.00 to 1234. I now how to export to CSV, but I need help with adjusting the result. Can you help me with that??? Quote Link to comment https://forums.phpfreaks.com/topic/106905-solved-export-to-csv/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 23, 2008 Share Posted May 23, 2008 To only select the first 35 characters of a field, use the mysql LEFT() function in your select statement - LEFT(str,len) Returns the leftmost len characters from the string str, or NULL if any argument is NULL. mysql> SELECT LEFT('foobarbar', 5); -> 'fooba' To format a number in your select statement use the mysql FORMAT() function - FORMAT(X,D) Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. mysql> SELECT FORMAT(12332.123456, 4); -> '12,332.1235' mysql> SELECT FORMAT(12332.1,4); -> '12,332.1000' mysql> SELECT FORMAT(12332.2,0); -> '12,332' Quote Link to comment https://forums.phpfreaks.com/topic/106905-solved-export-to-csv/#findComment-548106 Share on other sites More sharing options...
Haggis Posted May 23, 2008 Share Posted May 23, 2008 <?php $number = number_format (1234.567, 0, '', ''); echo $number; ?> this give the output 1235 coz it rounds up if you want 2 decimal places i.e. the pennies make it <?php $number = number_format (1234.567, 2, '', ''); echo $number; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106905-solved-export-to-csv/#findComment-548113 Share on other sites More sharing options...
budimir Posted May 24, 2008 Author Share Posted May 24, 2008 OK, I think I'm getting an idea. Thnx. Quote Link to comment https://forums.phpfreaks.com/topic/106905-solved-export-to-csv/#findComment-548807 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.