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

LVL 7
rgranlundAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
Your 'where' can't work.  Do
ORDER BY `id` DESC LIMIT 1

Open in new window

0
 
rgranlundAuthor Commented:
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

0
 
Dave BaldwinFixer of ProblemsCommented:
'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.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Dave BaldwinFixer of ProblemsCommented:
What worked?
0
 
rgranlundAuthor Commented:
Once you mention order by, I needed to look it up and it is ->order_by
0
 
Dave BaldwinFixer of ProblemsCommented:
Oh, thanks, good to know.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.