cache_num_row
#1

Hi. When I type /reports it shows that "There are no Reports" but at MySQL there are 6 reports.

Why?

PHP код:
CMD:reports(playeridparams[])
{
    if(
pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid,-1,""COL_RED"Not Admin!");
    new 
str[128], Cache:reports;
    
mysql_format(mysqlstrsizeof(str), "SELECT * FROM `reportlog`");
    
reports mysql_query(mysqlstrtrue);
    new 
count cache_num_rows();
    if(
count 0)
    {
         
SendClientMessage(playerid, -1"Reports:");
        for(new 
0counti++)
        {
            new 
reporter[25], reported[25], reportidreportedon[25], reportreason[25], showreps[450];
            
reportid cache_get_field_content_int(i"ID");
            
cache_get_field_content(i"Username"reporter);
            
cache_get_field_content(i"Targetname"reported);
            
cache_get_field_content(i"Data"reportedon);
            
cache_get_field_content(i"Report"reportreason);
            
format(showrepssizeof(showreps), "[#%d] (%s) %s has reported %s! [Reason: %s]"reportidreportedonreporterreportedreportreason);
            
SendClientMessage(playeridREDshowreps);
        }
    }
    else return 
SendClientMessage(playeridRED"There are currently no reports!");
    
cache_delete(reports);
    return 
1;

Mysql rows are: ID, Username, Targetname, Data, Report,
Reply
#2

What version of the mysql plugin are you using?
Reply
#3

Quote:
Originally Posted by Chyakka
Посмотреть сообщение
What version of the mysql plugin are you using?
R39.6
Reply
#4

Had you been using r41 this should work:

Код:
CMD:reports(playerid, params[]) 
{ 
    if(pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid,-1,""COL_RED"Not Admin!"); 
    new str[128]; 
    mysql_format(mysql, str, sizeof(str), "SELECT * FROM `reportlog`"); 
    mysql_tquery(mysql, str, "ShowReports", "u", playerid); 
    return 1; 
}  

forward ShowReports(playerid);
public ShowReports(playerid)
{
	if(cache_get_row_count() > 0)
	{
		SendClientMessage(playerid, -1, "Reports:"); 
        for(new i = 0; i < count; i++) 
        { 
            new reporter[25], reported[25], reportid, reportedon[25], reportreason[25], showreps[450]; 
            reportid = cache_get_field_content_int(i, "ID"); 
            cache_get_field_content(i, "Username", reporter); 
            cache_get_field_content(i, "Targetname", reported); 
            cache_get_field_content(i, "Data", reportedon); 
            cache_get_field_content(i, "Report", reportreason); 
            format(showreps, sizeof(showreps), "[#%d] (%s) %s has reported %s! [Reason: %s]", reportid, reportedon, reporter, reported, reportreason); 
            SendClientMessage(playerid, RED, showreps); 
        } 
	}
	else return SendClientMessage(playerid, RED, "There are currently no reports!"); 
	return 1;
}
You may be able to adapt this to work with your version (btw i'd recommend learning to use LIMIT in your queries that could potentially yield thousands of rows to avoid a database hiccup).
Reply
#5

Quote:
Originally Posted by Chyakka
Посмотреть сообщение
Had you been using r41 this should work:

Код:
CMD:reports(playerid, params[]) 
{ 
    if(pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid,-1,""COL_RED"Not Admin!"); 
    new str[128]; 
    mysql_format(mysql, str, sizeof(str), "SELECT * FROM `reportlog`"); 
    mysql_tquery(mysql, str, "ShowReports", "u", playerid); 
    return 1; 
}  

forward ShowReports(playerid);
public ShowReports(playerid)
{
	if(cache_get_row_count() > 0)
	{
		SendClientMessage(playerid, -1, "Reports:"); 
        for(new i = 0; i < count; i++) 
        { 
            new reporter[25], reported[25], reportid, reportedon[25], reportreason[25], showreps[450]; 
            reportid = cache_get_field_content_int(i, "ID"); 
            cache_get_field_content(i, "Username", reporter); 
            cache_get_field_content(i, "Targetname", reported); 
            cache_get_field_content(i, "Data", reportedon); 
            cache_get_field_content(i, "Report", reportreason); 
            format(showreps, sizeof(showreps), "[#%d] (%s) %s has reported %s! [Reason: %s]", reportid, reportedon, reporter, reported, reportreason); 
            SendClientMessage(playerid, RED, showreps); 
        } 
	}
	else return SendClientMessage(playerid, RED, "There are currently no reports!"); 
	return 1;
}
You may be able to adapt this to work with your version (btw i'd recommend learning to use using LIMIT in your queries that could potentially yield thousands of rows to avoid a database hiccup).

If I go for R41, I will have to rescript every single code and I don't want to.
Reply
#6

i think your problem is here:-
pawn Код:
new str[128], Cache:reports;
    mysql_format(mysql, str, sizeof(str), "SELECT * FROM `reportlog`");
    reports = mysql_query(mysql, str, true);
    new count = cache_num_rows();
it should be something like this
pawn Код:
new Cache:reports = mysql_query(mysql, "SELECT * FROM `reportlog`", true); //you really don tneed to use format
    new count = cache_num_rows(mysql); //forgot handle
Reply
#7

Still it shows me "There are no reports"

If i go for Chyakka's version it shows blank at /reports cmd
Reply
#8

The script it's modified by this topic

https://sampforum.blast.hk/showthread.php?tid=631555
Reply
#9

if it is storing data in ur database, then this should work
pawn Код:
CMD:reports(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid,-1,""COL_RED"Not Admin!");
    new Cache:reports = mysql_query(mysql, "SELECT * FROM `reportlog`", true);
    new rows = cache_num_rows(mysql), count = 0;
    SendClientMessage(playerid, -1, "Reports:");
    for(new i = 0; i < rows; i++)
    {
        new reporter[MAX_PLAYER_NAME], reported[MAX_PLAYER_NAME], reportid, reportedon[25], reportreason[25], showreps[200];
        reportid = cache_get_field_content_int(i, "ID");
        cache_get_field_content(i, "Username", reporter);
        cache_get_field_content(i, "Targetname", reported);
        cache_get_field_content(i, "Data", reportedon);
        cache_get_field_content(i, "Report", reportreason);
        format(showreps, sizeof(showreps), "[#%d] (%s) %s has reported %s! [Reason: %s]", reportid, reportedon, reporter, reported, reportreason);
        SendClientMessage(playerid, RED, showreps);
        count++;
    }
    if(count == 0)
    {
        SendClientMessage(playerid, RED, "There are currently no reports!");
    }
    cache_delete(reports);
    return 1;
}
otherwise, there might be errors in ur logs
Reply
#10

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
if it is storing data in ur database, then this should work

otherwise, there might be errors in ur logs
Tried your code, still the same error.


It saves, but still it shows there are no reports.


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)