FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


AUTO INCREMENT howto





imagefree
How can i start auto incrementing in mysql databases from any number other than 1?

I want it to start counting from 1000000000. How to do it?
AOP Web Development
just trying to help, hope this would work.

first
set your primary key ID into varchar let say varchar (Cool

then make a function to get the last key which is



Code:


function get_nextNum(){

$sql= 'SELECT MAX(Id) as MaxId from yourTable';
$rs = mysql_query($sql);
$row  = mysql_fetch_assoc($rs);
$lastId = intval($row['MaxId']);

if($lastId <= 0){

$NewId = '00000001';
}else{
$slen = strlen(trim($lastId));

for($i=8;$i>$slen;$i--)
$xZero.="0";

$NewId = $xZero.$lastId;
}

return $NewId;
}


I'm not sure if this is the correct one, didn't test it yet... but i hope you get an idea how to work on it. Smile
imagefree
cant understand Crying or Very sad Sad
traxion
way use php for that?

u can easy make 1 first record with the id 1000000. the rest will be 1+ automatically, when u have selected autoincresment in the database
golles
goto PHPMYADMIN
goto the database and click on structure or browse from the table
click on operations
in Table options set auto_increment to 1000000000

and you are done
AOP Web Development
Nice tip.... but also php function can be also useful if you trying to make something different style of number let say you are try to merge the deptID,dateadded and your number.

ex. 10072120001

something like that...
Related topics
[PhP] News Posting Tutorial (code, actually ^^')
What is useful way in this php+mysql problem?
Przenoszenie phpBB by przemo... tez tak mieliscie
How to create online form submission using phpmyadmin Sql
what is dump?
mySQL Query/PHP code - get the highest value...
Export and Import Mysql Table
[php] Php Editor
Ajuda!!!HElp
how to simplify these codes?
mail system......an mysql....
phpBB errors when people sign up
MySQL - phoneNo. input mask
AUTO INCREMENT VALUE
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.