query problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: query problem (/showthread.php?tid=22324) |
query problem - El Forum - 09-05-2009 [eluser]tim1965[/eluser] This is really confusing me and i would appreciate some help. I have a function that runs a search against two dates and an amount field. Function below function check_charges() { $price_per_week =($this->input->post('price_per_week', TRUE) == FALSE) ? '9999' : $this->input->post('price_per_week'); $start_date = ($this->input->post('start_date', TRUE) == FALSE) ? date('Y-m-d') : $this->input->post('start_date'); $end_date = ($this->input->post('end_date', TRUE) == FALSE) ? date('Y-m-d') : $this->input->post('end_date'); $t ="SELECT property_id FROM v_charges_date_price WHERE $start_date between `start_date1` and `end_date1` OR $end_date between `start_date1` and `end_date1` AND $price_per_week <= 'price_per_week_1' "; $query_results = $this->db->query($t); if($query_results->num_rows() >0) { $row=$query_results->result_array(); //var_dump($row); foreach ($row as $val){ $v=$val['property_id']; $charges=$v; //var_dump($charges); return $charges; } } If i var_dump$charges with the return commented out i get this which is correct (7 and 8) Quote:string(1) "7" string(1) "8" Quote:However if i then add the return the array only contains 7 and not 8 i.e. its dropping everything after the first result Quote:string(1) "7" Quote:My controller is Quote:$charges = $this->M_search_v1->check_charges(); Quote:Either i am missing something blindingly obvious or there is something funny going on here. All help appreciated. query problem - El Forum - 09-05-2009 [eluser]pistolPete[/eluser] Try this: Code: if($query_results->num_rows() >0) But why do you need to iterate over the results at all? Why don't you just use this: Code: return $query_results->result_array(); query problem - El Forum - 09-05-2009 [eluser]SitesByJoe[/eluser] I agree with pistolPete - change the way you're doing your loop etc. You're making things more complex than they need to be. |