Task: get display 10 objects except 1 specific Solutions:
get 11 objects from DB, and do something like this
foreach ($products as $product) { if($product->getId() != $specificProduct->getId()){ //display } }
just add condition in sql query
WHERE p.id != :specific_product_id
Some additional information: we use doctrine2 with mysql, so we must expect some additional time by hydration. I have made some test, I timed both of this solutions but I still haven't any idea which way is better.
So, I have gotten some strange results by my test(get 100 queries with different parameters)
- php = 0.19614
- dql = 0.16745
- php = 0.13542
- dql = 0.15531
Maybe someone have advice about how I should have made my test better