Dan Brown - Mortgage - Student Loans and Credit - Babb Fest - Loans

PDA

View Full Version : PHP Newbie question


Jim_Westergren
Aug 28th 2005, 6:03 am
Hi,

I will now make a table in MySQL and which will generate a HTML table with a list with PHP. This I know how to do. I also know how to do the form for inputting data in the db.

Now I would like that each entry gets an ID number. The first one #1 and then +1 after each input by the form. How do I do that?

The purpose of it is that I can change in the db by writing the ID number of the entry to be changed.

Thanks.

blinxdk
Aug 28th 2005, 6:21 am
Add the ID field to your mysql database, then select the result set using ORDER BY youridfield ASC;

That will order the result with the lowest numbers first, you can use DESC to reverse it.

If you want the entry in the database to automaticly get the idfield when you add it, you can assign it as autoincrement.

Jim_Westergren
Aug 28th 2005, 6:23 am
Add the ID field to your mysql database, then select the result set using ORDER BY youridfield ASC;

That will order the result with the lowest numbers first, you can use DESC to reverse it.

That I knew actually, but how do I get the ID numbers into the db? Or is that automatic?

blinxdk
Aug 28th 2005, 6:39 am
That I knew actually, but how do I get the ID numbers into the db? Or is that automatic?

If you're just creating the table, add an autoincrementing field.

If you have an existing table then use ALTER table ADD COLUMN.

Look here for more info: http://dev.mysql.com/doc/mysql/en/example-auto-increment.html

If you are using some tool to manage your db, then it proberly has functions for all of the above.

Jim_Westergren
Aug 28th 2005, 6:47 am
Thank you blinxdk.

I will do the table now so the autoincrementing is the way to go. Will learn it now.

Thanks.