How do I write a search query using Kohana PHP?
Question
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?
Solution
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.
OTHER TIPS
Here is what it would look like:
$arr = ORM::factory('product_shoppingcart')->where(
'shoppingcart_id',"=",$shoppingcartID)->find_all();
Shouldnt your table be "product_shoppingcarts" or am I missing something?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow