Count Issue
#1

pawn Код:
stock LoadFactions()
{
    new Query[400];
    fcount = 0;
    for(new id = 0;id<MAX_FACTIONS;id++)
    {
        format(Query, sizeof(Query), "SELECT * FROM Factions WHERE ID = %d", id);
        mysql_query(Query);
        mysql_store_result();
        fcount++;
        if(mysql_num_rows() != 0)
        {
           if(mysql_fetch_row_format(Query, "|"))
            {
                sscanf(Query, "p<|>s[30]dd",
           
                FactionInfo[id][Name],
                FactionInfo[id][Type],
                FactionInfo[id][FBank]);
                printf("%s | %d | %d", FactionInfo[id][Name],FactionInfo[id][Type],FactionInfo[id][FBank]);
            }
        }
    }
    printf("%i Faction Loaded",fcount);
   
    return 1;
}

I have this code, and i want it to count each faction it has found on the database. For starters, the printf(%s | etc doesn't show up in the console, at all, so I'm guess it doesnt load up at all. How could I fix this issue, and also count each faction found? Thanks in advance.
Reply
#2

Why would you loop MAX_FACTIONS amount of queries? I'm pretty sure I've said before not to do that with your code to you. Use mysql_retrieve_row to just go through all the lines in the database. You also never free the result .

pawn Код:
stock LoadFactions()
{
     new id = 0, rowfetch[300];
     mysql_query("SELECT * FROM Factions");
     mysql_store_result();
     while(mysql_retrieve_row())
     {
         id ++;
         mysql_fetch_row_format(rowfetch, "|")
         sscanf(rowfetch, "p<|>s[30]dd", FactionInfo[id][Name], FactionInfo[id][Type], FactionInfo[id][FBank]);
         printf("%s | %d | %d", FactionInfo[id][Name],FactionInfo[id][Type],FactionInfo[id][FBank]);
     }
     printf("%i Factions Loaded",id);
     mysql_free_result();
     return 1;
}
Reply
#3

Whoops. Thanks, I was just trying something like this and failed lol

pawn Код:
stock LoadFactions()
{
    new str[400];
    fcount = 0;
    new index;
    mysql_query("SELECT * FROM `Factions`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(str))
        {
       
            sscanf(str, "p<|>ds[30]dd",
            FactionInfo[index][ID],
            FactionInfo[index][Name],
            FactionInfo[index][Type],
            FactionInfo[index][FBank]);
            printf("%s | %d | %d glsgs", FactionInfo[index][Name],FactionInfo[index][Type],FactionInfo[index][FBank]);
            fcount++;
        }
    }
    mysql_free_result();
    printf("Loaded %d factions",index);
    return 1;
}
I'll try yours.
Reply
#4

"[22:37:58] | 0 | 0
[22:37:58] 1 Factions Loaded"

Is what is shows :/ It has values tho on the PHPMYADMIN.

pawn Код:
Police  1   500
Reply
#5

I'm pretty sure you can get rid of the loop and use the MYSQL SELECT COUNT query. ****** it since i'm on my phone now.
Reply
#6

pawn Код:
mysql_debug(1);
under OnGameModeInit and then paste your mysql log in your server directory.
Reply
#7

It doesn't show up in my mysql log and yes i have debug 1

edit: it does now

pawn Код:
CMySQLHandler::Query(SELECT * FROM Factions) - Successfully executed.

[23:20:34] >> mysql_store_result( Connection handle: 1 )

[23:20:34] CMySQLHandler::StoreResult() - Result was stored.

[23:20:34] >> mysql_retrieve_row( Connection handle: 1 )

[23:20:34] >> mysql_fetch_row_format( Connection handle: 1 )

[23:20:34] >> mysql_retrieve_row( Connection handle: 1 )

[23:20:34] >> mysql_free_result( Connection handle: 1 )

[23:20:34] CMySQLHandler::FreeResult() - Result was successfully free'd.
Reply
#8

bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)