SQL Query
#1

I have a problem with my Faction loading system.

I have this code:

pawn Код:
case D_THREAD_LOADFACTIONS:
        {
            mysql_store_result();
            if(mysql_num_rows() > 0)
            {
                new szResult[300];
                while(mysql_fetch_row_format(szResult, "|"))
                {
                    for(new row = 0; row < mysql_affected_rows(); row++)
                    {
                        sscanf(szResult, "e<p<|>ds[50]s[30]s[30]s[30]s[30]s[30]s[30]s[30]>", Factions[row]);
                        print(szResult);
                        iTotalFactions++;
                    }
                }
            }
        }

The problem is, is that it posts this on the console:

Код:
[13:55:24] 1|Angel Pine Sheriffs Department|Test|Test|None|None|None|None|Sheriff
[13:55:24] 1|Angel Pine Sheriffs Department|Test|Test|None|None|None|None|Sheriff
[13:55:24] 1|Angel Pine Sheriffs Department|Test|Test|None|None|None|None|Sheriff
[13:55:24] 1|Angel Pine Sheriffs Department|Test|Test|None|None|None|None|Sheriff
[13:55:24] 2|Angel Pine Medical & Fire Services|None|None|None|None|None|None|Chief of EMS.
[13:55:24] 2|Angel Pine Medical & Fire Services|None|None|None|None|None|None|Chief of EMS.
[13:55:24] 2|Angel Pine Medical & Fire Services|None|None|None|None|None|None|Chief of EMS.
[13:55:24] 2|Angel Pine Medical & Fire Services|None|None|None|None|None|None|Chief of EMS.
[13:55:24] 3|Bug Extermination Co.|None|None|None|None|None|None|Director
[13:55:24] 3|Bug Extermination Co.|None|None|None|None|None|None|Director
[13:55:24] 3|Bug Extermination Co.|None|None|None|None|None|None|Director
[13:55:24] 3|Bug Extermination Co.|None|None|None|None|None|None|Director
[13:55:24] 4|Grand Dragon Triad|None|None|None|None|None|None|None
[13:55:24] 4|Grand Dragon Triad|None|None|None|None|None|None|None
[13:55:24] 4|Grand Dragon Triad|None|None|None|None|None|None|None
[13:55:24] 4|Grand Dragon Triad|None|None|None|None|None|None|None
It loads each Faction 4 times, because there are 4 factions; it's confusing. All help is appreciated and rep will be distributed.
Reply
#2

Remove the for-loop, it is not necessary at all!
Reply
#3

Then what would I put for "sscanf(szResult, "e<p<|>ds[50]s[30]s[30]s[30]s[30]s[30]s[30]s[30]>", Factions[i]);" As it gives an error of undefined symbol.
Reply
#4

Please look up myqsl_affected_rows on the wiki. It's not supposed to be used like that. It returns the number of rows affected by - for example - an update query. It's not supposed to be used with a select query.
Reply
#5

I had this problem in PHP:

Don't use a FOR loop in a WHILE loop.
WHILE does the FOR for you.
Reply
#6

The loop is my mistake. I helped him write some code yesterday and obviously wasn't thinking clearly. I can obviously tell the loop isn't necessary, but here comes another problem: the faction enum needs a faction ID because it's set-up like this: Faction[factionid][fName]

What would "factionid" be then?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)