I'm tried to make year reporting with codeigniter. expectation output like this:
month 01 = 0 data, month 02 = 10 data and continuing...
Controller
$this->load->model('dash_model');
$data = array();
$data['mont'] = array$this->dash_model->monthreport();
$this->output->enable_profiler(TRUE);
$this->parser->parse('blank.htm', $data);
When I'm trying to write the code in PHP without CodeIgniter, it does work.
for($i=1; $i<=12; )
{
$month=array("","01","2","3","4","5","6","7","8","9","10","11","12");
$m = $month[$i];
$query = "SELECT count(*) as trans_email
FROM trans_email
WHERE lup LIKE '2014-$m%' ";
$qu = mysql_query($query);
$data=mysql_fetch_array($qu);
$komp = $data['trans_email'];
}
I tried to implement the above code to model CodeIgniter
dash model
for($i=1; $i<=12; )
{
$month=array("","01","2","3","4","5","6","7","8","9","10","11","12");
$m = $month[$i];
$query2=$this->db->query("SELECT count(*) as rr
FROM trans_email
WHERE lup LIKE '2014-$m%' ");
$resultArray[$i]=$query2->result_array();
$i++;
}
return $resultArray;
View
{mont}
month {rr}
{/mont}
and the results are not as expected.
How to return the query that was in an array of as many as 12 times and resulted in 12 outputs like this:
month 01 = 0 data, month 02 = 10 data and continuing...
How to query that I have a loop, its value can I throw into the controller
here's what i would do:
$months = array(
'01',
'02',
...
);
$this->db->select('count(*) as rr');
foreach($months as $month){
$this->db->like('lup', $month);
}
$query = $this->db->get('trans_email')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.