SA-MP Forums Archive
MYSQL Issue With ID Fetch - 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 Issue With ID Fetch (/showthread.php?tid=487392)



MYSQL Issue With ID Fetch - UnknownGamer - 13.01.2014

Hi,

What did I do wrong here, this should work? But it returns value 0, when ID should be 64?

pawn Код:
new query[256], cquery[256], vid;
                    mysql_format(dbhandle, query, sizeof query, "SELECT `id` FROM `vehicles` ORDER BY `id` DESC LIMIT 1 ;", vid);
                    mysql_tquery(dbhandle, query, "", "");
                   
                    format(cquery, sizeof(cquery), "UPDATE users SET car='%d' WHERE name='%s'", vid, sendername);
                    mysql_tquery(dbhandle, cquery, "", "");
                   
                    printf("Vehicle DB-ID: %d Saved to playername %s.", vid, sendername);



Re: MYSQL Issue With ID Fetch - Vince - 13.01.2014

Not sure how many times I've said it the past few weeks, but if you're using R7 or higher then you MUST use callbacks. Though in your case you could probably solve it with a subquery;

PHP код:
UPDATE users SET car=(SELECT MAX(`id`) FROM `vehicles`) WHERE name='%s' 



Re: MYSQL Issue With ID Fetch - UnknownGamer - 13.01.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
Not sure how many times I've said it the past few weeks, but if you're using R7 or higher then you MUST use callbacks. Though in your case you could probably solve it with a subquery;

PHP код:
UPDATE users SET car=(SELECT MAX(`id`) FROM `vehicles`) WHERE name='%s' 
You are a life savior.

+REP

Thankyou Vince :')!