raymeerwijk Posted September 16, 2017 Share Posted September 16, 2017 (edited) I've been working on this since yesterday but i can't get this to work like i want it too.I just want the results to order by date ascending instead of chronological order.My knowledge is really terrible and i have tried a several number of options.The only result is a page that keeps on loading.This is why i would like to ask for some help.I added an image of the things i have and the code is below public function getCustomerAppointments( $with_cancelled = false ) { $result = array(); if ( $this->get( 'id' ) ) { $appointments = CustomerAppointment::query( 'ca' ) ->select( 'ca.*, c.name, c.phone, c.email' ) ->leftJoin( 'Customer', 'c', 'c.id = ca.customer_id' ) ->where( 'ca.appointment_id', $this->get( 'id' ) ); if ( ! $with_cancelled ) { $appointments->whereNot( 'ca.status', Lib\Entities\CustomerAppointment::STATUS_CANCELLED ); $appointments->whereNot( 'ca.status', Lib\Entities\CustomerAppointment::STATUS_REJECTED ); } foreach ( $appointments->fetchArray() as $data ) { $ca = new CustomerAppointment( $data ); // Inject Customer entity. $ca->customer = new Customer(); $data['id'] = $data['customer_id']; $ca->customer->setFields( $data, true ); $result[] = $ca; } } return $result; } Hope you can help meRay Edited September 16, 2017 by raymeerwijk Quote Link to comment https://forums.phpfreaks.com/topic/305004-order-by-date/ Share on other sites More sharing options...
Barand Posted September 16, 2017 Share Posted September 16, 2017 Put an ORDER BY clause in your query. Quote Link to comment https://forums.phpfreaks.com/topic/305004-order-by-date/#findComment-1551404 Share on other sites More sharing options...
raymeerwijk Posted September 16, 2017 Author Share Posted September 16, 2017 That's exactly what i've been trying to do, but where ever i place it the page keeps on loading. Quote Link to comment https://forums.phpfreaks.com/topic/305004-order-by-date/#findComment-1551405 Share on other sites More sharing options...
Sepodati Posted September 18, 2017 Share Posted September 18, 2017 Based on how you're building your query, there's probably an ->orderby() method that you need to use. Kind of hard to get more specific than that without knowing what your database abstraction layer is doing. Quote Link to comment https://forums.phpfreaks.com/topic/305004-order-by-date/#findComment-1551513 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.