Welcome Guest, Not a member yet? Register   Sign In
Error with object and member of array
#1

[eluser]beecode[/eluser]
I try to get data from model by for loop from times to check.I don'know now i am correct about logics and code which I wrote. My program generate value from model initial value from 2 values that is times which recieve from input values.This is my views from.

<?php if($times>0): ?>
&lt;?php for($i=1;$i<=$times;$i++):?&gt;
<p>
<label>ช่วงที่ &lt;?php echo $i; ?&gt;ตรวจสอบตั้งแต่วันที่ </label>
&lt;input name="start_date&lt;?php echo $i; ?&gt;" id="start_date&lt;?php echo $i; ?&gt;" class="start_date times"/&gt;
<label>ถึงวันที่</label>
&lt;input name="end_date&lt;?php echo $i; ?&gt;" id="end_date&lt;?php echo $i; ?&gt;" class="end_date times" /&gt;
</p>
&lt;?php endfor; ?&gt;


Now i used 2 dimention arrays for keep data which get from models to send to view page this is my controller
for($i=1;$i<=$times;$i++){
$data['start_date'.$i] = $this->input->post('start_date'.$i);
$data['end_date'.$i] = $this->input->post('end_date'.$i);
//$start_date =1;
$start_date = $this->input->post('start_date'.$i);
$end_date = $this->input->post('end_date'.$i);

//echo $end_date.'<br />';
//$region = 'region'.$i;
$data['regions'][$i] = $this->areas_model->find_by_region($start_date,$end_date);
}
$this->areas_model->find_by_region($start_date,$end_date);

$this->load->view('charts/view_graph',$data);


This is my models.

function find_by_region($start_date,$end_date){
$sql = "SELECT `regionid` , SUM( `isa_2_area` ) AS Rai
FROM `doae_plantarea`
INNER JOIN doae_user ON ccaa_code = CONCAT( isa_1_location_provinceid, '000000' )
WHERE `isa_8_harvest_date` BETWEEN '".$start_date."' AND '".$end_date."'
GROUP BY doae_user.regionid";
$query = $this->db->query($sql);

return $query;
}


And Last view for generate graph.

<tbody>
<tr>
<th>Central region</th>
&lt;?php for($i=1;$i<=$times;$i++): ?&gt;
&lt;?php foreach($regions[$i]->result_array() as $region):?&gt;
&lt;?php
if($region['regionid']==1){
echo '<td>'.$region['Rai'].'</td>';
}
?&gt;
&lt;?php endforeach; ?&gt;
&lt;?php endfor; ?&gt;
</tr>
<tbody>


Actually now it ok for generate graph but some times I change $regions[$i]->result_array() to result() function when iterate to twice up it error about member array or object I don't know much.

Please help me for checkmy solution for performance and speed of code and SQL because I must query data from morethan 500,000 records..
#2

[eluser]maria clara[/eluser]
can you post the error message and the line of code pertains to it?
#3

[eluser]beecode[/eluser]
now it'swork but logic in the cot sure about code i'am not sure about performace
before i user this code error code like this Wcannot use object of type stdclass as array"

I use print_r() for view error it show when second of loop but in the first it OK'
#4

[eluser]beecode[/eluser]
Acctually, I want to now about logic to get data from model by loop. Can I use other logics for do this?? Thank you
#5

[eluser]maria clara[/eluser]
[quote author="beecode" date="1267774407"]now it'swork but logic in the cot sure about code i'am not sure about performace
before i user this code error code like this Wcannot use object of type stdclass as array"

I use print_r() for view error it show when second of loop but in the first it OK'[/quote]

yes,you can use other logic as long as its working and it follows the CI. can i see the code your telling me? please post it. thanks.
#6

[eluser]beecode[/eluser]
This error code
Code:
"Cannot use object of type stdclass as array"
#7

[eluser]maria clara[/eluser]
[quote author="beecode" date="1267775602"]This error code
Code:
"Cannot use object of type stdclass as array"
[/quote]

that's the error message. can you post the code that has that said error?




Theme © iAndrew 2016 - Forum software by © MyBB