SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/08/2014, 12:15 PM   #1
Giannidw
Little Clucker
 
Join Date: Nov 2012
Location: Brabant, Netherlands
Posts: 39
Reputation: 185
Default Select specific data MYSQL

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!
Giannidw is offline   Reply With Quote
Old 21/08/2014, 02:43 PM   #2
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,526
Reputation: 554
Default Re: Select specific data MYSQL

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)?
Misiur is offline   Reply With Quote
Old 21/08/2014, 03:02 PM   #3
Giannidw
Little Clucker
 
Join Date: Nov 2012
Location: Brabant, Netherlands
Posts: 39
Reputation: 185
Default Re: Select specific data MYSQL

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...
Giannidw is offline   Reply With Quote
Old 21/08/2014, 03:14 PM   #4
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,526
Reputation: 554
Default Re: Select specific data MYSQL

Well, then it's quite straightforward:
Code:
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 Code:
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)
Misiur is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL select a whole row Jeroen52 Scripting Help 2 22/05/2012 03:11 PM
MySQL Select Abreezy Scripting Help 3 13/02/2012 05:41 AM
[Help-SQL] I need help to select data InsaniManES Scripting Help 5 28/09/2011 10:35 AM
Mysql SELECT gedux123775 Help Archive 3 17/10/2010 10:33 AM
MySQl Select DB Matimor Server Support 5 10/10/2009 12:54 PM


All times are GMT. The time now is 07:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.