Unstoppable Domains

Auto numbering in MySQL?

Spaceship Spaceship
Watch

3GN Media

Established Member
Impact
8
Hey guys, I read a tutorial a long time ago on how to automatically have mysql number the rows but I forgot. Anyway, take a look at this for me:

Code:
$query = "INSERT INTO `games` VALUES (94, $cat, '$flash.swf', '$title', 0, 1, '$img.jpg', '400', '300', '$description', 24, '')";

Instead of putting 94 and changing it to 95, 96, etc. How can I make it so that it does automatically instead of having to manually change the number in the tables?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
"auto_increment" in phpmyadmin
 
1
•••
So do I just leave it blank in the query?
 
0
•••
In PHPMyAdmin select auto_increments for Extras and change the mysql query to

PHP:
$query = "INSERT INTO `games` VALUES ($cat, '$flash.swf', '$title', 0, 1, '$img.jpg', '400', '300', '$description', 24, '')";

Remove the 94 it will auto generate it.

iNod.
 
1
•••
Thanks for the help guys :)
 
0
•••
So will this work if I have in a table records 1, 2, 3, 4 and then i delete 2 will the next record added continue onto 5 then or will it be 4 giving me two 4's and causing a possible conflict
 
0
•••
Hey,

It will give you 5 :)

MySQL keeps tracks off the records.
 
0
•••
Another good and helpful tool is MySQL Control Center, that you can download.
 
0
•••
Is that possible to get the auto increment value after insert the record?
 
0
•••
I was gonna say just count the total rows, then make the total rows the file id. Or, simple order by ID, then add 1 to the last row. Perfect way of doing it, but I guess that is easier.
 
0
•••
tansks said:
Is that possible to get the auto increment value after insert the record?


If you are coding in PHP, you can use the mysql_insert_id() function.

-Bob
 
1
•••
iNod said:
In PHPMyAdmin select auto_increments for Extras and change the mysql query to

PHP:
$query = "INSERT INTO `games` VALUES ($cat, '$flash.swf', '$title', 0, 1, '$img.jpg', '400', '300', '$description', 24, '')";

Remove the 94 it will auto generate it.

iNod.

That wont work as sql will think that $cat is the first field. You can either have it so you explicitly name the table fields such as

PHP:
$query = "INSERT INTO `games` ('field1', 'field2', 'field3', 'field4', 'field5', 'field6', 'field7', 'field8', 'field9', 'field10')VALUES ($cat, '$flash.swf', '$title', 0, 1, '$img.jpg', '400', '300', '$description', 24, '')";

obviously changing the field names to their proper names or you can make it

PHP:
$query = "INSERT INTO `games` VALUES ('', $cat, '$flash.swf', '$title', 0, 1, '$img.jpg', '400', '300', '$description', 24, '')";
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back