MySQL Factions
#1

I'm wondering why this doesn't work. I haven't made a save function yet, as I find it a bit more challenging, but I inserted lines via Phpmyadmin and it doesn't load. Check this out, if you spot an error please tell me, thanks in advance.

pawn Код:
function LoadFactions()
{
    new faction;
    mysql_query("SELECT * FROM Factions");
    mysql_store_result();
    sscanf(str, "e<p<|>ds[64]fffs[32]s[32]s[32]s[32]s[32]s[32]>", factionInfo[faction][fID], factionInfo[faction][Fname],factionInfo[faction][fType],factionInfo[faction][fpositionx],factionInfo[faction][fpositiony],factionInfo[faction][fpositionz],factionInfo[faction][fRank1],factionInfo[faction][fRank2],factionInfo[faction][fRank3],factionInfo[faction][fRank4],factionInfo[faction][fRank5],factionInfo[faction][fRank6]);
    AddFactionIcons(faction);
    mysql_free_result();
    return 1;
   
}
pawn Код:
function AddFactionIcons(faction)
{
    format(str, sizeof(str), "[Faction]: %s[32] ", factionInfo[faction][Fname]);
    Create3DTextLabel(str, 0x008080FF, factionInfo[faction][fpositionx], factionInfo[faction][fpositiony], factionInfo[faction][fpositionz], 10.0, 0, 0);
   
    printf("** %d loaded", factionInfo[faction][fID]);
}

The Icons don't load at all, i'm not sure whats wrong, no errors occur.
Reply
#2

Well no wonder, there's nothing being stored in the "str" variable? You need to use mysql_fetch_row to get the data from the row and store it in an array. Also, you're not using sscanf as it is intended to be used with an enumerator, additionally, you're only going to be loading one faction with this snippet of code, when I assume you want to load multiple ones. For example:

pawn Код:
function LoadFactions()
{
    new faction;
    mysql_query("SELECT * FROM Factions");
    mysql_store_result();
    while(mysql_fetch_row(str))
    {
        sscanf(str, "e<p<|>ds[64]fffs[32]s[32]s[32]s[32]s[32]s[32]>", factionInfo[faction]);
        AddFactionIcons(faction);
        faction++;
    }
    mysql_free_result();
    return 1;
   
}
Now we're gathering the data from each row retrieved from the query, then using sscanf to split it, then incrementing the faction variable so that we're storing the data in the correct cell of the array the next time around.
Reply
#3

Alright, thanks for that correction, But now, How about adding the 3d text and such? It still doesn't show up at all.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)