SA-MP Forums Archive
MySQL 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 ID (/showthread.php?tid=663027)



MySQL ID - Kraeror - 19.01.2019

Hello guys, I have a question about MySQL inserting. I'm creating a house system. In my create house command I need to set the house's ID, but the problem is that I don't know how to check the next id of the house like in the table are:
1
2
3
5
IDS (without 4 because it's deleted) insert the house as ID 4.
I tried to count the lines (cache_num_rows()), but if I count them now it will make the new house with ID 5 in this case and there will be 2 houses with ID 5

I hope you understand me, sorry for my bad English!


Re: MySQL ID - Chyakka - 19.01.2019

If you just run the insert query like normal you can use the LAST_INSERT_ID mysql function to get the ID of it, don't think there's any reason for it to not work on the samp mysql plugin.


Re: MySQL ID - Hunud - 19.01.2019

You may do something based on this way in the buy house command.

Let's loop tho all houses for example.

Code:
for (hID = 1; hID < MAX_HOUSES; hID++)
After you are done with this, you have to check does the house/ r the house pickup exist. Let's say..

Code:
if (!IsValidDynamicPickup(.......[hID][HousePickup])) break; //Free House ID was found.