Jump to content

Export database data into different columns of a csv file


ethereal1m

Recommended Posts

Dear all,

I want to export data from database into a csv file using the following code:

function export()
	{

	$this->load->dbutil();
	$this->db->order_by('id','asc');
	$query = $this->db->get('some_table');
	$enclosure = '';
	$delimiter = ",";
	$newline = "\r\n";
	$data = $this->dbutil->csv_from_result($query,$delimiter,$newline,$enclosure);

		if ( ! write_file('my_directory\data.csv', $data))
		{
			echo 'Unable to write the file';
		}
		else
		{
			echo 'File written!';
		}
	}

Basically it uses csv_from_result to create the layout and later it is written to a file using write_file. I delimit each column with comma (,) and each row with carriage return. However when I open the file from Excel, each column is separated by comma and placed into one cell of Excel instead of different cells. Like this:

 

How can I make so that they are in different cells? What should I used for the arguments?

 

regards,

ethereal1m

Link to comment
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.