Jump to content
xisto Community
Sign in to follow this  
brawler

Php & Mysql Help need some help

Recommended Posts

I'm not sure whether i should have posted this here, but anyway. I am making an email-like system. I have a table that reads the "id", "subject", "author" and "date" off a mysql table. let's say that there are 15 messages in the table, but when i delete all the messages using a php script then post a new message the "id" sets itself to 16 instead of 1, the only way i have figured out is to Truncate the table and just fake it for now, and not allow deleting. I think i have to add in an update mysql table or something - how do i do this? if you would like to see inbox page its at http://forums.xisto.com/no_longer_exists/ and if you want to view the code just post back.

Share this post


Link to post
Share on other sites

It sounds like you are using 'auto_increment' for the ID field, the only way to reset the count is to truncate the table as you have discovered. If its the number of messages you are trying to find out, instead of using the ID field, why not count the records?This is easily done using a statement similar to this:$msgcount = mysql_num_rows(mysql_query("select ID from table_name"));Just change 'table_name' to name of your table and the $msgcount variable will now tell you how many records you have in your table.

Share this post


Link to post
Share on other sites

The whole point of the auto_increment function is to create a unique id for each record. Rather than MySQL waste processing power and time working out the highest number in the table it just picks up where it left off.Truncating the table does work but can also be a waste of time if you don't need the numbers to go from 1. I cannot see what purpose the id number serves on your mail system? Perhaps you would care to elaborate.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.