Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166511
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166524
Share on other sites

well i have a table called 'games'
------------------
game_id
name
icon (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
Link to comment
https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166534
Share on other sites

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. 
Link to comment
https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166548
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/35136-next-autoindex/#findComment-166552
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.