Jump to content

[SOLVED] Export to CSV!


budimir

Recommended Posts

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???

Link to comment
https://forums.phpfreaks.com/topic/106905-solved-export-to-csv/
Share on other sites

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'

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/106905-solved-export-to-csv/#findComment-548106
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.