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 am using ORH Kohana.

I want to write a search query that returns all rows where the column shoppingcart_id

contains 1 (for example).

I've already tried:

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

      

but it doesn't work.

Can anyone help me?

+1


a source to share


3 answers


Your example code should work, but maybe the problem is that you are 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 multiple lines with that ID, that should give you the result of the iterator into $ results, which you then walk around with a foreach loop. I have many examples of similar working code in case you still cannot get it to work.

+1


a source


This is how it looks:



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

      

+1


a source


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

0


a source







All Articles