SA-MP Forums Archive
Select specific data MYSQL - 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: Select specific data MYSQL (/showthread.php?tid=532930)



Select specific data MYSQL - Giannidw - 21.08.2014

Hey, i would like to get the data from a specific cell in MYSQL.
After that, i would also like to check if the data is 0 or 1.
Can someone help me?

Thanks!


Re: Select specific data MYSQL - Misiur - 21.08.2014

What is the type of this field? Are there any other possible values other than 0 or 1? Which MySQL plugin are you using? If BlueG one - version < R8, or most recent one (with usage of threaded queries)?


Re: Select specific data MYSQL - Giannidw - 21.08.2014

Type of the field is an Integer, and i use only 0 or 1, it changes from 0 to 1 when a user accept the rules. I use BlueG's MYSQL plugin, an older version i think. (DLL date is 2010), cause when i use a newer version, the MYSQL will not work...


Re: Select specific data MYSQL - Misiur - 21.08.2014

Well, then it's quite straightforward:
Код:
SELECT fieldname FROM yourtable WHERE somecondition = somevalue LIMIT
I can't recommend mysql_format as %e and few other arguments are broken before R9. Also bear in mind that I never wrote any unthreaded queries (and if you can, please upgrade to them before your server lags to death).
pawn Код:
new
    id = 666,
    query[64];

format(query, sizeof query, "SELECT fieldname FROM yourtable WHERE id = %d LIMIT 0, 1", id);

mysql_query(query);

mysql_store_result();
if(mysql_errno() != 0 || mysql_num_rows() == 0) {
    printf("[Err]: Something wrong when executing query with parameter %d", id);
} else {
    new
        fieldvalue = mysql_fetch_int();

    printf("Fetched value %d for %d!", fieldvalue, id);
}
mysql_free_result();
Of course change "fieldname" and "tablename", and change your where clause (and if your string gets longer watch out for size of query variable - it's only 64 at the moment)