woocha Posted January 13, 2008 Share Posted January 13, 2008 Hey Guys, I have a massive DB and want to search one of the fields titled site_id. I want to search the field for the highest number and then assign that number to a variable. This way I can have PHP add 1 to the variable and then insert it into a new field. The whole point of this is to get around the limit of 1 auto increment per table. Does anyone have any suggestions. Thanks Guys Link to comment https://forums.phpfreaks.com/topic/85806-mysql-query-and-order-by-highest-number-and-grab-highest-result/ Share on other sites More sharing options...
Barand Posted January 13, 2008 Share Posted January 13, 2008 SELECT MAX(site_id) FROM tablename Link to comment https://forums.phpfreaks.com/topic/85806-mysql-query-and-order-by-highest-number-and-grab-highest-result/#findComment-437918 Share on other sites More sharing options...
woocha Posted January 13, 2008 Author Share Posted January 13, 2008 SELECT MAX(site_id) FROM tablename Is that is the SQL query I should execute? Link to comment https://forums.phpfreaks.com/topic/85806-mysql-query-and-order-by-highest-number-and-grab-highest-result/#findComment-437930 Share on other sites More sharing options...
Barand Posted January 13, 2008 Share Posted January 13, 2008 yes <?php $res = mysql_query("SELECT MAX(site_id) FROM tablename"); $highest_site_id = mysql_result($res,0); Link to comment https://forums.phpfreaks.com/topic/85806-mysql-query-and-order-by-highest-number-and-grab-highest-result/#findComment-437954 Share on other sites More sharing options...
woocha Posted January 13, 2008 Author Share Posted January 13, 2008 Thanks Barand....You're awesome Link to comment https://forums.phpfreaks.com/topic/85806-mysql-query-and-order-by-highest-number-and-grab-highest-result/#findComment-437960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.