SA-MP Forums Archive
MySQL free ID - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL free ID (/showthread.php?tid=624503)



MySQL free ID - HidroDF - 17.12.2016

Hello, I'm trying to combine two tables in MySQL.

Code:

Код:
new query[400];
mysql_format(handle, query, sizeof(query), "INSERT INTO Phones SET Number = '%i'", phone);
mysql_tquery(handle, query, "", ""); // Tried InsertPhone here but same result
InsertPhone(number, cache_insert_id());

public InsertPhone(number, lastid)
{
new query[400];
mysql_format(handle, query, sizeof(query), "INSERT INTO ServerObjects (number, phoneid) VALUES ('%i', '%d')", number, lastid);
mysql_query(handle, query);
}
But the last id is 0 everytime. In the table Phones I have an ID row with AUTO_INCREMENT.
In Server I can't make the 'phoneid' as AUTO_INCREMENT because I don't insert only phones...

Any help?


Re: MySQL free ID - SickAttack - 17.12.2016

cache_insert_id() must be used in the callback specified with mysql_tquery, but you didn't specify one. You're using the callback/function wrong. Let mysql_tquery call it.


Respuesta: MySQL free ID - HidroDF - 17.12.2016

I've tried
Код:
mysql_tquery(handle, query, "InsertPhone", "id", number, cache_insert_id());
And don't work.


Re: Respuesta: MySQL free ID - SickAttack - 17.12.2016

Quote:
Originally Posted by HidroDF
Посмотреть сообщение
I've tried
Код:
mysql_tquery(handle, query, "InsertPhone", "id", number, cache_insert_id());
And don't work.
Put it directly:

mysql_format(handle, query, sizeof(query), "INSERT INTO ServerObjects (number, phoneid) VALUES ('%i', '%d')", number, cache_insert_id());


Respuesta: MySQL free ID - HidroDF - 17.12.2016

Worked, thanks!