Show all punishments command
#1

Hello Everyone,

I just made a database command called "Punishments" that needs to retrieve all the rows from a user ID and fetch them in to a variable called reasons and displays them on the screen. However when i run the command nothing happends because it does not retrieve those rows, anyone have any idea what is wrong with this database query?

Код:
COMMAND:punishments(playerid,params[]) {
	if(CheckARank(playerid, 2, 4)) {
	    new targetid;
	    if(!sscanf(params, "U(-1)", targetid)) {
	        if(targetid == -1) {
				new query[256];
				format(query, sizeof(query), "SELECT * FROM warnings WHERE warning_userid = '%d'", playersInfo[playerid][pID]);
				printf(query);
				new Result:warnings = mysql_query(mysql, query, QUERY_THREADED | QUERY_CACHED);
				new rows = mysql_num_rows(warnings);
				if(rows) {
					for(new go = 0; go < rows; go++) {
					    new reason[256];
					    mysql_get_field_assoc(warnings, "warning_reason", reason, 256);
					    SendClientMessage(playerid, COLOR_GREEN, reason);
					   db_next_row(DBResult:warnings);
					}
				} else {
				    SendClientMessage(playerid, COLOR_RED, "No warnings!");
				}
	        } else {
                new query[256];
				format(query, sizeof(query), "SELECT * FROM warnings WHERE warning_userid = '%d'", playersInfo[playerid][pID]);
				new Result:warnings = mysql_query(mysql, query, QUERY_THREADED);
				new rows = mysql_num_rows(warnings);
				for(new go = 0; go < rows; go++) {
				    new reason[256];
				    mysql_get_field_assoc(warnings, "warning_reason", reason, 256);
					SendClientMessage(playerid, COLOR_GREEN, reason);
					db_next_row(DBResult:warnings);
				}
	        }
	    } else {
	        SendClientMessage(playerid, COLOR_YELLOW, "(Usage!) /punishments [*playerid]");
	    }
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)