Foser Posted January 31, 2008 Share Posted January 31, 2008 Basic question. I want to do something like this $info = mysql_query("SELECT topic_title, topic_first_poster_name, topic_id, forum_id, topic_poster FROM phpbb_topics WHERE ..."); I want WHERE topic_id is the highest number. Thanks Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/ Share on other sites More sharing options...
nethnet Posted January 31, 2008 Share Posted January 31, 2008 <? $sql = "SELECT topic_title, topic_first_poster_name, topic_id, forum_id, topic_poster FROM phpbb_topics ORDER BY topic_id ASC LIMIT 1"; $info = mysql_query($sql) or die("Couldn't run the query."); ?> Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454253 Share on other sites More sharing options...
Foser Posted January 31, 2008 Author Share Posted January 31, 2008 I just want one ouput of the one with the biggest integer, not working.... Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454254 Share on other sites More sharing options...
nethnet Posted January 31, 2008 Share Posted January 31, 2008 "LIMIT 1" will return only one row from the database, and "ORDER BY topic_id DESC" will put all of the rows in reverse numerical order based on topic_id, so using them together will give you just one row, that being the highest topic_id... Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454258 Share on other sites More sharing options...
nethnet Posted January 31, 2008 Share Posted January 31, 2008 Just realized that in my first post I put ORDER BY topic_id ASC. The ASC should be DESC if you want the highest number. The other way will give you the lowest number. Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.