CodeIgniter and csv_from_result

2019-09-18 04:17发布

问题:

I have getting data from a database and using

$query = $this->db->query("SELECT * FROM mytable");

echo $this->dbutil->csv_from_result($query);

however I want to change the name of my headers for the CSV for first_name is First Name...how would I go about doing that?

Thanks, J

回答1:

Try renaming the columns returned by the sql query:

$query = $this->db->query("
    SELECT 
         first_name as 'First Name', last_name as 'Last Name' 
    FROM mytable
");

The downside is that you will have to list the columns instead of a simple *.