Prismatic Posted September 26, 2006 Share Posted September 26, 2006 Im having a big brain fart on this one :PI have a table setup like this[quote][u]message_id | chat_id | user_id | user_name | message | post_time[/u]233 |1 |10 |Bob |Test |2006-09-26 16:11:02234 |1 |10 |Bob |Weee |2006-09-26 16:12:32235 |1 |10 |Bob |Arr! |2006-09-26 16:14:56etc..[/quote]What I need to do is run a query to grab the HIGHEST message_id in the table, anyone know what a query like that would look like? Sorry, im having a bad day hehThanks! Link to comment https://forums.phpfreaks.com/topic/22183-return-highest-field-number-from-query/ Share on other sites More sharing options...
sanfly Posted September 26, 2006 Share Posted September 26, 2006 Something like this should do it$r = mysql_query("SELECT * FROM messages ORDER BY message_id DESC LIMIT 1") or die(mysql_error());EDIT: Added limit Link to comment https://forums.phpfreaks.com/topic/22183-return-highest-field-number-from-query/#findComment-99318 Share on other sites More sharing options...
High_-_Tek Posted September 27, 2006 Share Posted September 27, 2006 "SELECT MAX(`message_id') as message_id FROM `TABLENAME`"The MySQL-driven functions are VERY powerful Link to comment https://forums.phpfreaks.com/topic/22183-return-highest-field-number-from-query/#findComment-99342 Share on other sites More sharing options...
HuggieBear Posted September 27, 2006 Share Posted September 27, 2006 Could even be simplified to:[code=php:0]$sql = "SELECT max(message_id) FROM tablename";[/code]If you're just going to us an alias of exactly the same name, surely there's no point?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/22183-return-highest-field-number-from-query/#findComment-99556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.