• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database queries

#1
[eluser]ozy123[/eluser]
I have a general question regarding model functions.

So I have some data I want to present in two tables. Right now I've coded a new function everytime I need slightly different data from the same table. I'm just wondering if this is the right way to do things or if there is a better way? I know that's a vague question but I get the feeling I'm doing something wrong.

// Retrieves bookings where status: 2/3/4
public function get_bookings($userid)
{
$query = $this->db->query("select * from booking where (status = 2 or status = 3 or status = 4) and uid = '$userid' and date >= CURDATE() order by Date");
return $query->result_array();
}

// Retrieves bookings where status 3 limit to three

public function get_bookingsl($userid)
{
$query = $this->db->query("select * from booking where status = 3 and uid = '$userid' order by Date LIMIT 3");
return $query->result_array();
}

// Retrieves bookings where status 3 and date < current date

public function get_complete_bookings($userid)
{
$query = $this->db->query("select * from booking where status = 3 and date < CURDATE() and uid = '$userid' order by Date DESC");
return $query->result_array();
}

#2
[eluser]NotDior[/eluser]
I think it's going to come down to personal preference and perhaps on a large scale performance.

Your other option, is to make a generic get all statement and then put the logic into your controller or your view(s).

#3
[eluser]ozy123[/eluser]
Ah ok. That makes sense. I'll stick with the logic in the model for now and see if I encounter problems. THanks for replying.

#4
[eluser]jmadsen[/eluser]
the more functions you write, the more functions you have to maintain.

try using some parameters


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.