SA-MP Forums Archive
Count ID's in SQL - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Count ID's in SQL (/showthread.php?tid=257808)



Count ID's in SQL - Fj0rtizFredde - 27.05.2011

Hi. I need some help with my SQL code... Im trying to get the last ID that was inserted in my database. It seems like the code Im using only counts the first 10 records.. I dont really know why. Maybe somebody knows why? I made 2 diffrent functions they both outputs the value: 9 (witch is the first 10 records in my database.) Somehow the code work if there is less then 10 records but not if there is more.. (This happens to both my functions) Did I do something wrong?

Simple version:
pawn Код:
stock GetLastIDSimple()
{
    new DBResult:qresult, string[128];
    qresult = db_query(GPSDB,"SELECT * FROM `System` ORDER BY `ID` DESC LIMIT 1");
    db_get_field(qresult,0,string,128);
    printf("Output %d", strval(string));
    db_free_result(qresult);
    return 1;
}



Re: Count ID's in SQL - Fj0rtizFredde - 28.05.2011

Bump (12 hours+)


Re: Count ID's in SQL - Haydz - 28.05.2011

If your sql ID's don't skip numbers you could use mysql_num_rows() to count how many rows are in the database, however if your numbers arn't in order this wouldn't work.


Re: Count ID's in SQL - Fj0rtizFredde - 28.05.2011

First of all this is SQLite and not mysql. The numbers are only in order as long as I dont delete them from the database. Im just trying to get the highest number in the database but it only works for the first 10 records


Re: Count ID's in SQL - Fj0rtizFredde - 29.05.2011

I think I got to bump this agian.. I cant find the problem.. I also tried to use SELECT MAX(id) but its still the same output.. Maybe anyone got another function that I could play around with?


Re: Count ID's in SQL - Fj0rtizFredde - 29.05.2011

Well ******, the first thing works perfect (thanks a lot ) but if I lets say have 10 records and I delete number 7 so the ID's now will go from 0-6 then 8-9 then the code just returns 0.. Is there a way to fix that or should I just skip the whole function instead and try to find another way?


Re: Count ID's in SQL - Fj0rtizFredde - 29.05.2011

Yes I did and it just returns 0 (both with and without "FROM `System`") Im just looking for a way to get the higest number from the ID's (Im sorry if that was not clear enough in my posts and I might even did it wrong from the start..) Like if I have ID 0-10 even if I delete number 5,6 or even 1 it should still give me the result of 10.. I hope you get what I mean