MySQL select a whole row
#1

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)