Welcome Guest, Not a member yet? Register   Sign In
csv_from_result only returning column labels
#1
Thumbs Down 

I'm looking to use CSV from result to produce a CSV file from a query; my code is like this;
PHP Code:
                   $delimiter ",";
 
                   $newline "\r\n";
 
                   $enclosure '"';
 
                   $data $this->dbutil->csv_from_result($query$delimiter$newline$enclosure);
 
                   force_download($fileLabel.'.csv'$data); 

and only returns the following
Code:
"learnerID","NameFirst","NameLast","MobileNumber"
Which is the column labels when I know the results do have entries (as is shown in this vardump of the $query put though the result_array)
Code:
array (size=3)
 0 =>
   array (size=4)
     'learnerID' => string '17' (length=2)
     'NameFirst' => string 'Test' (length=4)
     'NameLast' => string 'Case' (length=4)
     'MobileNumber' => string '7000000000' (length=10)
 1 =>
   array (size=4)
     'learnerID' => string '18' (length=2)
     'NameFirst' => string 'Case' (length=4)
     'NameLast' => string 'Test' (length=4)
     'MobileNumber' => string '7000000000' (length=10)
 2 =>
   array (size=4)
     'learnerID' => string '19' (length=2)
     'NameFirst' => string 'a' (length=1)
     'NameLast' => string 'b' (length=1)
     'MobileNumber' => string 'c' (length=1)
What am I doing wrong?
Reply
#2

Maybe your sql statement is wrong? You should have somethink like that:

Code:
$query = $this->db->query("SELECT learnerID, NameFirst, NameLast, MobileNumber FROM your_table");

Reply
#3

(This post was last modified: 05-05-2017, 03:29 AM by CraigAMcLeod.)

(05-05-2017, 01:47 AM)Rufnex Wrote: Maybe your sql statement is wrong? You should have somethink like that:

Code:
$query = $this->db->query("SELECT learnerID, NameFirst, NameLast, MobileNumber FROM your_table");

It's like this:
PHP Code:
           ->select('learnerID , NameFirst, NameLast, MobileNumber')
 
           ->from('learner'/*The table*/
 
           ->where('Status',$learner_status)
 
           ->where_not_in('learnerID'$excluded_learnerID_list)
 
           $query $this->db->get(); 
It produces the results just fine but the csv only outputs the one line.

Edit: shot in the dark, here's my csv_from_result code.
PHP Code:
$delimiter ",";
                    
$newline "\r\n";
                    
$enclosure '"';
                    
$data $this->dbutil->csv_from_result($query$delimiter$newline$enclosure);
                    
force_download($fileLabel.'.csv'$data); 
Reply
#4

OK I found my problem, essiently using $query = $this->db->get(); basicly futzes with $query's object and makes it useless for csv_from_result.

OK, that found out I now have an issue as I do not know how to get the query builder to generate an object and not a Missing argument 1 for CI_DB_driver::list_fields() result.

I tried using "get_compiled_select" but that doesn't work.

I need the query builder to work with CSV_from_result.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB