MySQL select a whole row - 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 select a whole row (
/showthread.php?tid=344592)
MySQL select a whole row -
Jeroen52 - 21.05.2012
It explains itself but what I want is selecting a row by using a string like
Код:
Columns: | Code |ID | Amount
_____________________________________________________________________
Rows: |XXX-ADF-994-421 |46 |500
|LOL-A-EXAMPLE0 |32 |21
|COOOOOOODEE |42 |42
These are just examples but what if a player is using a command like /redeem [code], how to select the code and copy all data into the server vars?
Re: MySQL select a whole row -
Mandrakke - 22.05.2012
pawn Код:
new Query[299]; // On the top
new temp[50]; // Inside OnPlayerCommandText
new Code[30]; // Inside OnPlayerCommandText
new ID; // Inside OnPlayerCommandText
new Amount; // Inside OnPlayerCommandText
// The code below should be in the command '/redeem' condition
format(Query, sizeof(Query), "SELECT * FROM table_name_change_here WHERE Code = '%s' LIMIT 0,1", code);
mysql_query(Query);
mysql_store_result();
if(mysql_retrieve_row()) {
mysql_fetch_field_row(temp, "Code"); format(Code, sizeof(Code), "%s", temp);
mysql_fetch_field_row(temp, "ID"); ID = strval(temp);
mysql_fetch_field_row(temp, "Amount"); Amount = strval(temp);
}
mysql_free_result();
Re: MySQL select a whole row -
Jeroen52 - 22.05.2012
Quote:
Originally Posted by Mandrakke
pawn Код:
new Query[299]; // On the top new temp[50]; // Inside OnPlayerCommandText new Code[30]; // Inside OnPlayerCommandText new ID; // Inside OnPlayerCommandText new Amount; // Inside OnPlayerCommandText
// The code below should be in the command '/redeem' condition format(Query, sizeof(Query), "SELECT * FROM table_name_change_here WHERE Code = '%s' LIMIT 0,1", code); mysql_query(Query); mysql_store_result();
if(mysql_retrieve_row()) { mysql_fetch_field_row(temp, "Code"); format(Code, sizeof(Code), "%s", temp); mysql_fetch_field_row(temp, "ID"); ID = strval(temp); mysql_fetch_field_row(temp, "Amount"); Amount = strval(temp); }
mysql_free_result();
|
Thanks!