Welcome Guest, Not a member yet? Register   Sign In
Problems with ActiveRecord: where($array)
#1

[eluser]Benedikt[/eluser]
Hi,

I use ActiveRecord for querying my databases. I implemented my own function to check if a row exists in the database already.

Basically it works when I pass just one parameter as "where":
Code:
$query = $this->db->select($col)->from($tbl)->where($val)->get();
But when I pass an associative array as where-parameter, it returns "no row found".

My array $var looks like this:
Code:
$var = array (
                'passport' => $data['passport'],
                'country'  => $data['country']
      );

I checked if the array passed to the function is filled and it is. Is this a bug in 1.6.3 or am I hving a mistake?

Thanks for your help,
Ben.
#2

[eluser]zimco[/eluser]
You might want to look at the user's manual for get_where

Code:
$query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);

It will do a much better job of explaining than i ever could, and i'm a bit of a newbie myself and don't want to send you on a wild goose-chase through your code.
#3

[eluser]Michael Wales[/eluser]
Code:
if_exists($params = array()) {
  if ((count($params) > 0) && (is_array($params))) {
    $query = $this->db->get_where('table', $params, 1, 0);
    if ($query->num_rows() > 0) {
      return TRUE;
    }
  }
  return FALSE;
}
#4

[eluser]Benedikt[/eluser]
Ok, I see. Thank you for your help.

But there is one paragraph which confuses me (I followed this paragraph):

"Associative array method: $array = array('name' => $name, 'title' => $title, 'status' => $status);

$this->db->where($array);

// Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'"

Is this just not working in chaining or not working in general?


EDIT:

Seems Im using it wrong:
Code:
$query = $this->db->select('id')->get_where('mytable', $var, 1, 0);
This doesnt work. How can I make it work with chaining?
#5

[eluser]Benedikt[/eluser]
Ok, got it to work like that:

Code:
$query = $this->db->select($col)->from($tbl)->get_where($tbl, $val, 1, 0);




Theme © iAndrew 2016 - Forum software by © MyBB