Rachid O
Rachid O

Reputation: 14052

Codeigniter datamapper returns all rows instead of one

When i execute this code I got 2 as result instead of 1:

          $a = $this->load->model('account');
          //$a->where('id', $_POST['id'])->get(); also gives 2
          //$a->where('salt', $_POST['salt'])->get(); also gives 2
          // echo $_POST['id'] returns "2" as expected and $_POST['salt'] is also valid
          $a->where('id', $_POST['id'])->where('salt', $_POST['salt'])->get();
          echo $a->count(); // returns 2

But in my data base i have two rows with ids 1,2 and differents salts

Upvotes: 0

Views: 43

Answers (1)

Mysteryos
Mysteryos

Reputation: 5791

$a->count() is counting all rows in your table.

What you want is:

$result = $a->where('id', $_POST['id'])->where('salt', $_POST['salt'])->get();
echo count($result);

So that you are counting the number of rows returned by your query.

Upvotes: 1

Related Questions