ShoeLace1291 Posted October 9, 2007 Share Posted October 9, 2007 Is there a way to show the next auto increment like in PHPMyAdmin for a certain table? Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/ Share on other sites More sharing options...
Barand Posted October 9, 2007 Share Posted October 9, 2007 The only time you will need it is when you insert a new record in one table and then insert linked records into a child table. insert parent record. call mysql_insert_id() to get its id insert child records with value returned by the function as foreign key Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/#findComment-365792 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 maybe SELECT MAX(id) FROM table unless the last one was deleted! may i ask why ? surely your use mysql_insert_id int mysql_insert_id ( [resource $link_identifier] ) Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/#findComment-365793 Share on other sites More sharing options...
Barand Posted October 9, 2007 Share Posted October 9, 2007 MadTechie, mysql_insert_id() - Got that one covered Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/#findComment-365796 Share on other sites More sharing options...
sasa Posted October 9, 2007 Share Posted October 9, 2007 <?php mysql_connect('localhost'); mysql_select_db('test'); $table_name = 'matches'; //change to your table name $sql = "SHOW TABLE STATUS LIKE '$table_name'"; $res = mysql_query($sql) or die(mysql_error()); $r = mysql_fetch_array($res); echo 'Next auto increment number for table ', $table_name, ' is ', $r['Auto_increment']; ?> Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/#findComment-365799 Share on other sites More sharing options...
ShoeLace1291 Posted October 10, 2007 Author Share Posted October 10, 2007 The only time you will need it is when you insert a new record in one table and then insert linked records into a child table. insert parent record. call mysql_insert_id() to get its id insert child records with value returned by the function as foreign key Actually I need it to redirect my users to a thread or poll they just created in the same page. Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/#findComment-365814 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 if they just created it, then when you create it use mysql_insert_id() to get the id, and pass that! Link to comment https://forums.phpfreaks.com/topic/72543-show-next-auto-increment-for-table/#findComment-365821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.