Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Query builder - column not found
  • I have this:
    $query = DB::select('offers.id', DB::expr("(SELECT COUNT( coupons.id ) FROM coupons WHERE 
    coupons.status = 'Y' AND coupons.offer_id = offers.id) AS `coupons_sold`"))
       ->from('offers')
       ->where('offers.status', 'IN', array('P', 'S'))
       ->where('offers.published_at', '<', $tomorrowMidnight)
       ->where('offers.end_at', '>', time())
       ->where('coupons_sold', '<', DB::expr('offers.max_available'))
       ->order_by('offers.created_at', 'DESC');
    

    but I get and error Fuel\Core\Database_Exception [ Error ]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'coupons_sold' in 'where clause' with query... The ouput SQL is otherwise OK, I can run it on my database. Any tips on how can I fix this?

Howdy, Stranger!

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

In this Discussion