Help with mysql
#1

This command just show 1 result, i want 5 results
How i can do it?

pawn Код:
CMD:searchban(playerid, params[])
{
    new bName[24];

    if(pData[playerid][P_Admin] < 2) return
        SendClientMessage(playerid, COLOR_RED, LV_Fail);

    if(sscanf(params,"s[24]", bName)) return
        SendClientMessage(playerid, COLOR_RED, "Use: /searchban <Name/IP>");

    new cQuery[1024], savingstring[256];

    format(cQuery, sizeof(cQuery), "SELECT * FROM bans WHERE Name LIKE '%%%s%%' or IP LIKE '%%%s%%' ORDER BY Ban_ID DESC LIMIT 5", params, params);
    mysql_query(MySQL, cQuery);
    mysql_store_result();

    new
        BannedBy[24],
        BannedName[24],
        BannedIP[24],
        BannedReason[24],
        BannedDay,
        BannedMonth,
        BannedYear,
        BannedHour,
        BannedMinute
    ;

    if(mysql_num_rows() > 0) {
        mysql_fetch_field_row(BannedBy, "Admin");
        mysql_fetch_field_row(BannedReason, "Reason");
        mysql_fetch_field_row(savingstring, "Day"); BannedDay = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Month"); BannedMonth = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Year"); BannedYear = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Hour"); BannedHour = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Minute"); BannedMinute = strval(savingstring);
        mysql_fetch_field_row(BannedName, "Name");
        mysql_fetch_field_row(BannedIP, "IP");

        format(cQuery, sizeof(cQuery),"%s banned %s(%s) for %s [%02d/%02d/%02d - %02d:%02d]\n",
            BannedBy,
            BannedName,
            BannedIP,
            BannedReason,
            BannedDay,
            BannedMonth,
            BannedYear,
            BannedHour,
            BannedMinute
        );
        SendClientMessage(playerid, COLOR_YELLOW, cQuery);
    } else {
        SendClientMessage(playerid, COLOR_RED, "No bans found.");
    }
    return 1;
}
Reply
#2

You need to loop trough all the rows.

Since you are using mysql_fetch_field_row you need to use mysql_retrieve_row() to move internal row pointer to the next row

Код:
if(mysql_num_rows() > 0) {
	while(mysql_retrieve_row())
	{
		mysql_fetch_field_row(BannedBy, "Admin");
		mysql_fetch_field_row(BannedReason, "Reason");
		mysql_fetch_field_row(savingstring, "Day"); BannedDay = strval(savingstring);
		mysql_fetch_field_row(savingstring, "Month"); BannedMonth = strval(savingstring);
		mysql_fetch_field_row(savingstring, "Year"); BannedYear = strval(savingstring);
		mysql_fetch_field_row(savingstring, "Hour"); BannedHour = strval(savingstring);
		mysql_fetch_field_row(savingstring, "Minute"); BannedMinute = strval(savingstring);
		mysql_fetch_field_row(BannedName, "Name");
		mysql_fetch_field_row(BannedIP, "IP");

		format(cQuery, sizeof(cQuery),"%s banned %s(%s) for %s [%02d/%02d/%02d - %02d:%02d]\n",
			BannedBy,
			BannedName,
			BannedIP,
			BannedReason,
			BannedDay,
			BannedMonth,
			BannedYear,
			BannedHour,
			BannedMinute
		);
		SendClientMessage(playerid, COLOR_YELLOW, cQuery);
	}
} else {
	SendClientMessage(playerid, COLOR_RED, "No bans found.");
}
Reply
#3

Working perfect, thank you dude! rep += 2;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)