wepnop Posted June 5, 2011 Share Posted June 5, 2011 I need to get the max of the field called ID, from the table ordenador. This is my actual code: $cons = "SELECT MAX(ID) FROM `ordenador`"; $maxrow = consultar_bd($cons); $id_contiene = $maxrow['ID']; consultar_bd is a function that executes a sql query and returns a fetched result as a array. Quote Link to comment https://forums.phpfreaks.com/topic/238477-geting-max-of-a-mysql-field/ Share on other sites More sharing options...
Pikachu2000 Posted June 5, 2011 Share Posted June 5, 2011 It seems you've neglected to ask a question . . . Quote Link to comment https://forums.phpfreaks.com/topic/238477-geting-max-of-a-mysql-field/#findComment-1225435 Share on other sites More sharing options...
wepnop Posted June 5, 2011 Author Share Posted June 5, 2011 Sorry maybe its that my english is bad, but i think i asked it: What i need is to get the max of the ID value in the ordenador table using php + mysql. Thats the code i was using but it dont works, when i try to get the ID it says that index dont exist. I need some way to know and store in a php variable what is the higest ID value. Quote Link to comment https://forums.phpfreaks.com/topic/238477-geting-max-of-a-mysql-field/#findComment-1225447 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 I sort of under stand can you do a orderby desc and the pick the first id so you get the highest number ? Do you have a feild ID in the ordenador table or is it id $cons = "SELECT `id` FROM `ordenador` ORDERBY DESC LIMIT =1"; Quote Link to comment https://forums.phpfreaks.com/topic/238477-geting-max-of-a-mysql-field/#findComment-1225461 Share on other sites More sharing options...
wepnop Posted June 5, 2011 Author Share Posted June 5, 2011 I sort of under stand can you do a orderby desc and the pick the first id so you get the highest number ? thanks, its working! Quote Link to comment https://forums.phpfreaks.com/topic/238477-geting-max-of-a-mysql-field/#findComment-1225464 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 just have to click solved now. Quote Link to comment https://forums.phpfreaks.com/topic/238477-geting-max-of-a-mysql-field/#findComment-1225476 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.