Destramic Posted January 21, 2007 Share Posted January 21, 2007 just wondering how i could get the next Autoindex of a table?thanks ricky Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/ Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 get the highest one and add one?$sql = "SELECT id FROM table ORDER BY id DESC LIMIT 1"; Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-165842 Share on other sites More sharing options...
Destramic Posted January 22, 2007 Author Share Posted January 22, 2007 nope that wouldnt work...would just be like using [code]mysql_num_rows() + 1;[/code]basically if there has been 10 entries to the database and you've deleted the 2 recent entries, then mysql_num_rows would return 8 which infact i would need it to return the next index which would be 11.hope someone can help ?thanks ricky Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166511 Share on other sites More sharing options...
Orio Posted January 22, 2007 Share Posted January 22, 2007 First- why do you need it? Maybe there's a simple way doing it, you just need to provide more information...The best thing I can think of is to insert a new record, run [url=http://www.php.net/manual/en/function.mysql-insert-id.php]mysql_insert_id()[/url] and add one to the result and then delete the record.But as I said- if you just want to know what will be the id of the next new record, you can simply insert it and then use mysql_insert_id(). It really depends on what you're asking for.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166524 Share on other sites More sharing options...
Destramic Posted January 22, 2007 Author Share Posted January 22, 2007 well i have a table called 'games'------------------game_idnameicon (will be saved as /images/icons/"game_id".gif)-----------------so i need to get the next autoindex of the game before it has been inserted so i can insert the icon uri...?thanks ricky Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166534 Share on other sites More sharing options...
ShogunWarrior Posted January 22, 2007 Share Posted January 22, 2007 Although it seems irritating I'd do an insert, get mysql_insert_id and then update the table with the icon URL. Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166537 Share on other sites More sharing options...
.josh Posted January 22, 2007 Share Posted January 22, 2007 you don't need to insert the number in auto_incrementing columns. just leave it blank and mysql will automatically fill it in. Hence the [i]auto[/i]-increment. Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166541 Share on other sites More sharing options...
ShogunWarrior Posted January 22, 2007 Share Posted January 22, 2007 Yes, but apparently he wants to name the image file with it's corresponding row, before he has inserted it. Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166544 Share on other sites More sharing options...
.josh Posted January 22, 2007 Share Posted January 22, 2007 well to be honest, I don't really see the point in that. One of the points of having a database is to seperate data from identifiers. That's why you have an id column in the first place. adding on the id number to the image name and then putting it into the table that already has the id number associated with it is at best, redundant. Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166548 Share on other sites More sharing options...
Orio Posted January 22, 2007 Share Posted January 22, 2007 Ok, I made a research and found the answer. Run this:[code]<?php$tbl_name = "games";$result1 = mysql_query("SELECT MAX(game_id) AS id FROM `$tbl_name`");$info1 = mysql_fetch_array($result1);echo "Current last id: ".$info1['id']."<br>";$result2 = mysql_query("SHOW TABLE STATUS LIKE '$tbl_name'");$info2 = mysql_fetch_array($result2);echo "Next id will be: ".$info2['Auto_increment'];?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166552 Share on other sites More sharing options...
Destramic Posted January 22, 2007 Author Share Posted January 22, 2007 thank you very much :D Quote Link to comment https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166572 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.