Select specific data MYSQL
#1

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!
Reply
#2

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)?
Reply
#3

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...
Reply
#4

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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)