Welcome Guest, Not a member yet? Register   Sign In
Use select_min in model function query
#1

[eluser]Unknown[/eluser]
Hi all
I have a little problem using "$this->db->select_min" in a model function.
I have 2 functions in model: first must return all results if a clause is true (this works fine).
The second one must select and return the smallest value finded in database column table for each row from first function.

First function
Code:
function recomended_offers($id)
{
  $data = array();
  $this->db->where('id_locality =', $id);
  $this->db->where('recomended =', 'yes');
  $this->db->limit('8', '0');
  $query1 = $this->db->get('locations');
  foreach($query1->result() as $row1):
   $data[] = $row1;
  endforeach;
  return $data;
}
Second function
Code:
function recomended_offers_price($recomended_offers)
{
  $data = array();
  
  //$this->db->select_min('week_price');
  
  $this->db->order_by("week_price", "desc");
  
  $query = $this->db->get('locations_price');
  
     //if ($query->num_rows() > 0)
           //{
           //$data[$row->id_location] = $row;
          // return $data;
     //}
  
  foreach ($query->result() as $row):
   $data[$row->id_location] = $row;
   endforeach;
  return $data;
}
In table "locations_price" each location from first function have several price values coresponding. Unfortunely the use of order by DESC or ASC will not return to me the smallest value because the values are in random order inserted in this column and i had not any key in this column to use so order by statement return me the corect value.
The commented lines from seconf function I tried to use for selecting smallest value but with no luck




Theme © iAndrew 2016 - Forum software by © MyBB