-1

I have a database : example database

I want to retrieve data with conditions where the card number is 7689, with product ID 73 or 71.

 $this->cekModel->where('card_number', 7689)->where('id_product ', '73')orWhere('id_product', '71')->FindAll();

The result must display 2 data, i.e. which has id = 1 and id = 4 but I only get one data using the query above

GMB
  • 216,147
  • 25
  • 84
  • 135
Riska Nanda
  • 129
  • 2
  • 13
  • Must? You’re wrong. Are you aware how the “or” condition works? – Mike Doe Jul 29 '20 at 14:18
  • actually I use the code $ this-> checkModel-> where ('card_number', 7689) -> where ('id_product', '73') but it only returns one record – Riska Nanda Jul 29 '20 at 14:20
  • Results from mysql queries are always right, unless you have found a bug in mysql, which you did not. – Luuk Jul 29 '20 at 14:24
  • other things aside, isn't it supposed to be `or_where`? – Muhammad Hamza Jul 29 '20 at 14:24
  • [or_where() was formerly known as orwhere(), which has been removed.](https://codeigniter.com/userguide3/database/query_builder.html#looking-for-specific-data) – Luuk Jul 29 '20 at 14:27
  • `$this-> checkModel-> where ('card_number', 7689) -> where ('id_product', '73')` is supposed to return only one result. – Muhammad Hamza Jul 29 '20 at 14:35

2 Answers2

1

Doesn't whereIn() do what you want?

$this->cekModel
    ->where('card_number', 7689)
    ->whereIn('id_product', array(71, 73))
    ->FindAll();
GMB
  • 216,147
  • 25
  • 84
  • 135
0
$this->cekModel
->where('card_number', 7689)
->whereIn('id_product', array(71, 73))
->FindAll();

The code above does not work correctly on my console (returns wrong results). I tried modification and it worked.

 $data=['71','73'];
 $this->cekModel
    ->where('card_number', 7689)
    ->whereIn('id_product', $data)
    ->FindAll();

Thank you..

Riska Nanda
  • 129
  • 2
  • 13