PDA

View Full Version : SQL Query


iGetty
16/01/2012, 08:17 PM
I have a problem with my Faction loading system.

I have this code:

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.

AndreT
16/01/2012, 08:31 PM
Remove the for-loop, it is not necessary at all!

iGetty
16/01/2012, 08:35 PM
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.

Vince
16/01/2012, 09:08 PM
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.

SchurmanCQC
16/01/2012, 09:12 PM
I had this problem in PHP:

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

Scenario
16/01/2012, 10:24 PM
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?