Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.