Attilah
Attilah

Reputation: 17930

How do I write a search query using Kohana PHP?

I have a table (product_shoppingcart) with 4 columns :

id, product_id, shoppingcart_id, product_quantity.

I'm using Kohana's ORM.

I want to write a search query which returns all the rows where the shoppingcart_id column contains 1 (for example).

I already tried:

$arr = ORM::factory('product_shoppingcart')->where('shoppingcart_id',$shoppingcartID)->find_all();

but that doesn't work.

Can anyone please help me out?

Upvotes: 1

Views: 1667

Answers (3)

Hardik
Hardik

Reputation: 11

Here is what it would look like:

$arr = ORM::factory('product_shoppingcart')->where(
                    'shoppingcart_id',"=",$shoppingcartID)->find_all();

Upvotes: 1

Bharat Mediratta
Bharat Mediratta

Reputation: 476

Your example code should work, but perhaps the problem is that you're not iterating over your result set?

$results = ORM::factory('product_shoppingcart')
           ->where('shoppingcart_id', $shoppingcartID)
           ->find_all();
foreach ($results as $product_shoppingcart) {
  print Kohana::debug($product_shoppingcart->as_array());
}

If you have more than one row with that id, this should give you a result iterator in $results, which you then walk with the foreach loop. I have lots of examples of similar working code, if you're still not able to get it working.

Upvotes: 1

sydlawrence
sydlawrence

Reputation: 1892

Shouldnt your table be "product_shoppingcarts" or am I missing something?

Upvotes: 0

Related Questions