AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Mysql update AUTO_INCREMENT id. (https://forums.alliedmods.net/showthread.php?t=229287)

w2zzaaa 11-04-2013 17:40

Mysql update AUTO_INCREMENT id.
 
...

YamiKaitou 11-04-2013 17:43

Re: Mysql update AUTO_INCREMENT id.
 
Why do you need to add another column? It is already tracking the SteamID.

mottzi 11-05-2013 13:16

Re: Mysql update AUTO_INCREMENT id.
 
explain bether what you want to do.

Backstabnoob 11-05-2013 13:37

Re: Mysql update AUTO_INCREMENT id.
 
I have no idea what you're saying, but if you need the id of the latest record added to the database, use SQL_GetInsertId. This will only give you the latest id of a row added by the handle of the plugin, so it will return something you don't want after you restart the server. To make it consistent, you will have to run a SELECT query, such as
Quote:

SELECT id FROM table ORDER BY id DESC LIMIT 0,1

Backstabnoob 11-05-2013 13:39

Re: Mysql update AUTO_INCREMENT id.
 
If you think these are stupid questions then you should probably figure out that your English and ability to explain the problem are severely lacking.

mottzi 11-05-2013 14:23

Re: Mysql update AUTO_INCREMENT id.
 
no, just explain bether (other words, other example) what your approach is. I dont understand what you want...

YamiKaitou 11-05-2013 14:55

Re: Mysql update AUTO_INCREMENT id.
 
If that is why you think you need ID, then it is wrong. Based on what you have shown so far, the existing record is updated based on SteamID and MapName. Maybe if you provide more code, we can understand what you are trying to do.

YamiKaitou 11-05-2013 15:29

Re: Mysql update AUTO_INCREMENT id.
 
The problem is that you have not clearly explained yourself. So, I am going to guess at what you are talking about

You had an existing table and then you added a new column and set it to Auto_Increment. When you do this, you need to MANUALLY set the Auto_Increment value on all existing data and then MANUALLY change the Next Auto_Increment value to the actual next value.

If you have an existing table with data, you need to determine the ID of the row you want to update before you actually update it, otherwise your query will insert a new row or fail for having more than 1 match.

YamiKaitou 11-05-2013 15:56

Re: Mysql update AUTO_INCREMENT id.
 
Quote:

Originally Posted by w2zzaaa (Post 2057282)
No i dont need :D i just try and this automatically update all old and new values.

Must be a feature of a newer MySQL version, I don't remember it doing it last time I tried (been some time)

Quote:

Like is said, i know exactly i need this. I know how to do this in php language, but i dont know how put this in plugin.
Then give us the PHP code for exactly what you want, maybe we can understand that better and help convert it

bcKq 11-05-2013 16:05

Re: Mysql update AUTO_INCREMENT id.
 
First you have to do
PHP Code:

SELECT id FROM table_name WHERE 1=1 ORDER BY id DESC LIMIT 0,

this will give u the max id (latest player added), get that id from that query,
PHP Code:

id++ 

then
PHP Code:

UPDATE 'blabla' SET id='%d' (and here you place new id

This will update and the player's ID will be the newest entry added
(don't know exact queries that you want to make but you get the idea, use the first one, then id = id+1 and update)


All times are GMT -4. The time now is 23:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.