22.05.2017, 17:25
Before i reply with an updated pastebin link, can you update the fields you're writing initially as 0 in the /makebusiness command to default value 0? Saves you an extra query.
Edit:
Looking at the code now, you can create either a new ID for it at runtime, by iterating all businesses, and getting a free ID that way, or this way:
It might also be worth setting default values (like i mentioned above), to save lines of code, and query length. You might also want to reload the businesses when they're created, or load the last one at least.
That should load the last created ID.
Edit:
Looking at the code now, you can create either a new ID for it at runtime, by iterating all businesses, and getting a free ID that way, or this way:
pawn Код:
//Your code to create / SQL etc
mysql_tquery(Database, query, "OnBusinessCreated", "i", playerid);
//You may of needed to thread the query for cache_insert_id(); to work (i only use threaded so i'm unsure if mysql_query(); supports it.
forward OnBusinessCreated(playerid);
public OnBusinessCreated(playerid)
{
new string[141];
format(string, sizeof(string), "Business %d created successfully", cache_insert_id());
SendClientMessage(playerid, COLOR_WHITE, string);
//You'd unload and load businesses here.
return 1;
}
pawn Код:
SELECT * FROM `businesses` ORDER BY `id` DESC LIMIT 1