Raised This Month: $32 Target: $400
 8% 

Solved Problem with printing MySQL table stuff


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
heroicpower7613
Member
Join Date: Nov 2016
Old 10-21-2017 , 23:30   Problem with printing MySQL table stuff
Reply With Quote #1

hello, i pulled this code from here to one of my plugins:
https://forums.alliedmods.net/showthread.php?t=220916

code:
PHP Code:
            char SteamID[64];
            
GetClientAuthId(itargetAuthId_Steam2SteamIDsizeof(SteamID));
            
g_SteamID SteamID;
    
            new 
String:Query[255];
            
Format(Querysizeof(Query), "SELECT * FROM ctban_log WHERE perp_steamid = '%s'"SteamID); 
                    
            
// Send our Query to the Function
            
if( client != 0)
                
SQL_TQuery(gH_BanDatabaseSQL_ReadAllQueryGetClientUserId(client));
                    

public 
SQL_ReadAll(Handle:ownerHandle:hndl, const String:error[], any:data)
{

    new 
client GetClientOfUserId(data);
    
    if (!
SQL_FetchRow(hndl))
    {
        
PrintToConsole(client" ");
        
PrintToConsole(client"No history.");
        return;
    }
        
    new 
iresults;
    
    
// We need to know the rowcount, in this case 2-1 because field begins at 0
    
new RowCount SQL_GetFieldCount(hndl);
    
    
// Temp, just for debugging or so
    
new field;
    
field++;
    
    
// Buffer for our result
    
new String:Buffer[255];
    
    
PrintToConsole(client" ");
    
PrintToConsole(client" ");
    
PrintToConsole(client"All SteamID results:");
    
    while(
SQL_FetchRow(hndl))
    {
        
iresults++;
        
        if(
field <= 7)
            
PrintToConsole(client"------------------Ban #%d------------------"field);
        
        for(new 
0iRowCounti++)
        {    
            if(
field 7)
            {
                
PrintToConsole(client" ");
                
PrintToConsole(client"Listing 1 - 7"); 
                
PrintToConsole(client"%T""ct_banlist_more_8"LANG_SERVER);
                return;
            }
            
            
SQL_FetchString(hndliBuffersizeof(Buffer));
            
            if (
StrContains(Buffer"-1"false) == 0)
                
Buffer "No timeleft";
            
            if (
StrContains(Buffer"0"false) == 0)
                
Buffer "Perm";
            
            if(
== 1)
                
PrintToConsole(client"Field %d | Row: %d | SteamID: %s"fieldiBuffer);
            if(
== 2) {
                
PrintToConsole(client"Field %d | Row: %d | Nick: %s"fieldiBuffer);
                
PrintToConsole(client" ");
                
PrintToConsole(client"Banned by:");
            }
            if(
== 3) {
                if (
StrEqual(Buffer"STEAM_0:1:1"))
                    
PrintToConsole(client"Field %d | Row: %d | Admin SteamID: Console"fieldi);
                else
                
PrintToConsole(client"Field %d | Row: %d | Admin SteamID: %s"fieldiBuffer);
            }
            if(
== 4) {
                
PrintToConsole(client"Field %d | Row: %d | Admin nick: %s"fieldiBuffer);
                
PrintToConsole(client" ");
            }
            if(
== 5)
                
PrintToConsole(client"Field %d | Row: %d | Time: %s"fieldiBuffer);
            if(
== 6)
                
PrintToConsole(client"Field %d | Row: %d | Timeleft: %s"fieldiBuffer);
            if(
== 7)
                
PrintToConsole(client"Field %d | Row: %d | Reason: %s"fieldiBuffer);
        }
        
PrintToConsole(client"------------------------------------------");
        
PrintToConsole(client" ");
        
field++;
    }
    
    
PrintToConsole(client" ");
    
PrintToConsole(client"Listing 1 - 7"); 
    
PrintToConsole(client" ");

its getting all results found for target's steamid from a mysql table.

but its basically skipping the very first result and doesn't print it.
it starts printing from the second result.

is there any fix for this?

to clarify, its skipping the first result that i marked with a red line:

Last edited by heroicpower7613; 10-22-2017 at 14:39.
heroicpower7613 is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 10-22-2017 , 03:22   Re: Problem with printing MySQL table stuff
Reply With Quote #2

Might be due to the first SQL_FetchRow:
PHP Code:
if (!SQL_FetchRow(hndl)) 

    
PrintToConsole(client" "); 
    
PrintToConsole(client"No history."); 
    return; 

hmmmmm is offline
heroicpower7613
Member
Join Date: Nov 2016
Old 10-22-2017 , 14:39   Re: Problem with printing MySQL table stuff
Reply With Quote #3

you right
PHP Code:
public SQL_ReadAll(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    new 
client GetClientOfUserId(data);
        
    new 
iresults;
    
    
// We need to know the rowcount, in this case 2-1 because field begins at 0
    
new RowCount SQL_GetFieldCount(hndl);
    
    
// Temp, just for debugging or so
    
new field;
    
field++;
    
    
// Buffer for our result
    
new String:Buffer[255];
    
    
PrintToConsole(client" ");
    
PrintToConsole(client" ");
    
PrintToConsole(client"All SteamID results:");
    
    while(
SQL_FetchRow(hndl))
    {
        
iresults++;
        
        if(
field <= 7)
            
PrintToConsole(client"------------------Ban #%d------------------"field);
        
        for(new 
0iRowCounti++)
        {    
            if(
field 7)
            {
                
PrintToConsole(client" ");
                
PrintToConsole(client"Listing 1 - 7"); 
                
PrintToConsole(client"%T""ct_banlist_more_8"LANG_SERVER);
                return;
            }
            
            
SQL_FetchString(hndliBuffersizeof(Buffer));
            
            if (
StrContains(Buffer"-1"false) == 0)
                
Buffer "No timeleft";
            
            if (
StrContains(Buffer"0"false) == 0)
                
Buffer "Perm";
            
            if(
== 1)
                
PrintToConsole(client"Field %d | Row: %d | SteamID: %s"fieldiBuffer);
            if(
== 2) {
                
PrintToConsole(client"Field %d | Row: %d | Nick: %s"fieldiBuffer);
                
PrintToConsole(client" ");
                
PrintToConsole(client"Banned by:");
            }
            if(
== 3) {
                if (
StrEqual(Buffer"STEAM_0:1:1"))
                    
PrintToConsole(client"Field %d | Row: %d | Admin SteamID: Console"fieldi);
                else
                
PrintToConsole(client"Field %d | Row: %d | Admin SteamID: %s"fieldiBuffer);
            }
            if(
== 4) {
                
PrintToConsole(client"Field %d | Row: %d | Admin nick: %s"fieldiBuffer);
                
PrintToConsole(client" ");
            }
            if(
== 5)
                
PrintToConsole(client"Field %d | Row: %d | Time: %s"fieldiBuffer);
            if(
== 6)
                
PrintToConsole(client"Field %d | Row: %d | Timeleft: %s"fieldiBuffer);
            if(
== 7)
                
PrintToConsole(client"Field %d | Row: %d | Reason: %s"fieldiBuffer);
        }
        
PrintToConsole(client"------------------------------------------");
        
PrintToConsole(client" ");
        
field++;
    }

    if(
iresults == 0)
    {
        
PrintToConsole(client" ");
        
PrintToConsole(client"No history.");
        return;
    }
    
    
PrintToConsole(client" ");
    
PrintToConsole(client"Listing 1 - 7"); 
    
PrintToConsole(client" ");

heroicpower7613 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode