Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP latest date

How would you write a query if you were trying to find the last entry / the latest entry?

$order_query = $this->EE->db->select('*')
					->where('member_id', $member)
					->where('status', 'open')
                                     [b]   ->where('id', 'WHERE ID IS THE HIGHEST NUMBER')[/b]
					->get('exp_cartthrob_subscriptions');

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

When I do it that way, I get this error:
Fatal error: Call to undefined method CI_DB_mysql_driver::orderby()
<?php
		$order_query = $this->EE->db->select('*')
					->where('member_id', $member)
					->where('status', 'open')
					->orderby('order_id', 'desc')
					->get('exp_cartthrob_subscriptions');

Open in new window

'ORDER BY' is standard SQL.  I have no idea what 'CI_DB_mysql_driver' is.  But if it doesn't support 'ORDER BY' then it is wrong.  Simply wrong.  Do some research, that can't be right.  Maybe there is a different way of doing it.
What worked?
Once you mention order by, I needed to look it up and it is ->order_by
Oh, thanks, good to know.