SQL Query - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQL Query (
/showthread.php?tid=311459)
SQL Query -
iGetty - 16.01.2012
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.
Re: SQL Query -
AndreT - 16.01.2012
Remove the for-loop, it is not necessary at all!
Re: SQL Query -
iGetty - 16.01.2012
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.
Re: SQL Query -
Vince - 16.01.2012
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.
Re: SQL Query -
SchurmanCQC - 16.01.2012
I had this problem in PHP:
Don't use a FOR loop in a WHILE loop.
WHILE does the FOR for you.
Re: SQL Query -
Scenario - 16.01.2012
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?