Error with object and member of array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Error with object and member of array (/showthread.php?tid=28211) |
Error with object and member of array - El Forum - 03-04-2010 [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): ?> <?php for($i=1;$i<=$times;$i++):?> <p> <label>ช่วงที่ <?php echo $i; ?>ตรวจสอบตั้งแต่วันที่ </label> <input name="start_date<?php echo $i; ?>" id="start_date<?php echo $i; ?>" class="start_date times"/> <label>ถึงวันที่</label> <input name="end_date<?php echo $i; ?>" id="end_date<?php echo $i; ?>" class="end_date times" /> </p> <?php endfor; ?> 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> <?php for($i=1;$i<=$times;$i++): ?> <?php foreach($regions[$i]->result_array() as $region):?> <?php if($region['regionid']==1){ echo '<td>'.$region['Rai'].'</td>'; } ?> <?php endforeach; ?> <?php endfor; ?> </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.. Error with object and member of array - El Forum - 03-04-2010 [eluser]maria clara[/eluser] can you post the error message and the line of code pertains to it? Error with object and member of array - El Forum - 03-04-2010 [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' Error with object and member of array - El Forum - 03-04-2010 [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 Error with object and member of array - El Forum - 03-04-2010 [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. Error with object and member of array - El Forum - 03-04-2010 [eluser]beecode[/eluser] This error code Code: "Cannot use object of type stdclass as array" Error with object and member of array - El Forum - 03-04-2010 [eluser]maria clara[/eluser] [quote author="beecode" date="1267775602"]This error code Code: "Cannot use object of type stdclass as array" that's the error message. can you post the code that has that said error? |