new in php
Moderator: General Moderators
new in php
hello guys please help me i want to us some a little bit question.. im new in php development my problem is i want to create increting number and insert to mysql.. just like auto increment but i want to use php code.. and they have condition if the is change the incrementation is back to one.. advance thank you.. please help me... 
Re: new in php
Don't do this. It's an incredibly bad idea. It's something that on the face of it is really simple, but to do it properly you'll have to solve loads of problems like locking, race conditions, speed, etc. The people who code databases have spent years tackling those issues, so there's no point redoing it all yourself. Go back to the client and figure out a proper solution.
Re: new in php
I agree with onion2k. Practical database design is definitely not intuitive. Things that seem logical to "ordinary" people often create substantial problems in databases. As onion2k said, computer scientists have spent decades establishing rules about database design principles. Follow their advice unless you think that you know more about it than they do.onion2k wrote:Don't do this. It's an incredibly bad idea. It's something that on the face of it is really simple, but to do it properly you'll have to solve loads of problems like locking, race conditions, speed, etc. The people who code databases have spent years tackling those issues, so there's no point redoing it all yourself. Go back to the client and figure out a proper solution.
Re: new in php
Thank you for the advice but I forgot to specified my previous question the specification of may question is the number I want to increment number leading seven zeroes or zerofill from left just like this 00000001 to 10000000 and if the current year is increment the number is go back to seven zero + 1. And also if the increment number reach the maximum also to 00000001. All of this is storing to mysql so anyone wants to post code for this question. Help me and thank you again… 
Re: new in php
If I understand correctly, you're generating ids along the lines of 2008-0000001, 2008-00000002. If the ids run out before the end of the year, you reuse ids.
How about using a MyISAM table with a multi column autoincrement.
How about using a MyISAM table with a multi column autoincrement.
As for restricting to seven digits and wrapping, let the database generate a unique id, which is always useful, and take the modulo and format it.For MyISAM and BDB tables you can specify AUTO_INCREMENT on a secondary column in a multiple-column index. In this case, the generated value for the AUTO_INCREMENT column is calculated as MAX(auto_increment_column) + 1 WHERE prefix=given-prefix.
Re: new in php
yes, but im not familliar to myisam.. any Suggestion
Re: new in php
It's just a type of table in mysql. Try this out:
Code: Select all
create table t(y year, id int unsigned not null auto_increment, primary key(y,id)) engine=MyISAM;
insert into t(y) values(2008);
insert into t(y) values(2008);
select * from t;
Re: new in php
any php code??for this question? 
Re: new in php
No, because solving this problem with PHP is the wrong way to approach it. It's a data issue, so it should be solved with the database if possible.<?erick?> wrote:any php code??for this question?
Frankly the idea of reusing database keys when you're only storing 100 million records sounds silly anyway. That's a lot of data, but MySQL can cope with a lot more.
@dml: Nice idea. I didn't know you could use multiple columns for an auto increment. That's sweet.
Re: new in php
Thank you for you all suggestion.. 