Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best practise: Total results + Limit / Offset
  • Hey, I'm looking for a best practise solution for this problem: I query the database with an SELECT statement with Limit and Offset, but I also want to have the total numbers of results, so I execute 2 queries right now:
    // total
    $query = Model_Artist::find($artistId, array(
                        'related' => array(
                            'products'
                        ),
                    ));
            $total = $products->count();
    
    // the wanted products
    $query = Model_Artist::find($artistId, array(
                        'related' => array(
                            'products' => array(
                                'order_by' => array('products.id' => 'DESC'),
                                'limit' => $limit,
                                'offset' => $start,
                            ),
                        ),
                    ));
    $products = $query->to_array();
    

    Is there a nicer / quicker / prettier way for this? I know that MySQL has an option (Found rows):
    http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_found-rows Thanks in advance!
  • Then you'll go to three queries. And currently this can not be implemented, because our Query Builder generates SQL-92 code, and can't deal with the specifics of an RDBMS engine. Improving this is on the roadmap.
  • Okay, thanks for the quick reply!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion