// This is inside an if statement, which explains the indentation.
new reason[128]; // Variable I would like to store the result in.
format(query, sizeof(query), "SELECT reason FROM `bans` WHERE IP = '%s'", GetName(playerid)); // Format query (I already got the player's IP)
mysql_query(query);// Store query
mysql_store_result();// Store the result
// And here is where I want to store the result into a variable
format(ccstring, sizeof(ccstring), "We're sorry but you're IP is banned from the server.\nIf you would like to appeal, please appeal on our website\nat {0320FF}"website"\n\nReason: %s", reason); // Format the dialog
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "{FF0303}[X]{FFFFFF} Banned", ccstring, "Okay", ""); // Show the dialog
Kick(playerid); // Kick the player because he's banned.
// Rest of code
format(query, sizeof(query), "SELECT reason FROM `bans` WHERE IP = '%s'", GetName(playerid));
new reason[64]; // Your reason will be stored in this
mysql_query("SELECT reason FROM bans"); // Fetch the reason and store it in a row
mysql_store_result(); // Store the resulting row in the buffer
if(mysql_retrieve_row()) {
mysql_fetch_field("reason", reason); // Fetch the "reason" field from the stored row, and place it in the reason variable
}
mysql_free_result(); // Free the buffer
printf("The reason is: %s", reason);
new data[128];
format(query, sizeof(query),"SELECT * FROM bans WHERE IP = '%s'",GetName(playerid)); //GetName? It says IP, well...
mysql_query(query), mysql_store_result();
if(mysql_num_rows())
{
mysql_get_field("reason", data);
format(ccstring, sizeof(ccstring), "We're sorry but you're IP is banned from the server.\nIf you would like to appeal, please appeal on our website\nat {0320FF}"website"\n\nReason: %s", data); // Format the dialog
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "{FF0303}[X]{FFFFFF} Banned", ccstring, "Okay", ""); // Show the dialog
Kick(playerid);
}
mysql_free_result();
mysql_query("SELECT reason FROM bans");
pawn Код:
The answer to your question: to fetch a value from a row do the following. pawn Код:
|
// Code removed
Try this:
EDIT: @Sinner: I think you have a little mistake here: What if there are many fields with more reasons? I mean many fields with different IPs and reasons. How do you know which one is the correct field? |