mysql problem - 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: mysql problem (
/showthread.php?tid=304120)
mysql problem -
Tanush123 - 17.12.2011
Well when i use /orgs it gets the org id right (i made 1 org that is id0) but the org name and leader is wrong and it spams like shit
pawn Код:
CMD:orgs(playerid,params[])
{
new orgsid,orgsname[50],lname[30];
new orgcounting = 1;
SendClientMessage(playerid,-1,"---------------------------Organizations------------------------");
for(new i = 0;i<MAX_ORGS;i++)
{
format(query, sizeof(query), "SELECT * FROM orgs");
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(query, sizeof(query), "SELECT * FROM orgs WHERE Orgid = '%d',Name = '%s',Leader = '%s'",orgsid,orgsname,lname);
mysql_query(query);
format(str, sizeof(str), "Organization ID: %d || Organization Name: %s || Organization Leader: %s",orgsid,orgsname,lname);
SendClientMessage(playerid,-1,str);
orgcounting++;
}
if(orgcounting == 1)
{
SendClientMessage(playerid,red,"ERROR: There is no organization created.");
}
}
return 1;
}
Re: mysql problem -
[HiC]TheKiller - 17.12.2011
pawn Код:
for(new i = 0;i<MAX_ORGS;i++)
Why? You're are retrieving the whole table MAX_ORGS times.
I'll rewrite the whole thing for you.
pawn Код:
CMD:orgs(playerid,params[])
{
new orgsid, orgsname[50],lname[30], orgstr[150];
format(query, sizeof(query), "SELECT * FROM orgs"); //This shouldn't be used too often
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() == 0)
{
mysql_free_result();
return SendClientMessage(playerid, -1, "There are no organisations!");
}
SendClientMessage(playerid, -1, "Organizations:");
while(mysql_retrieve_row())
{
//You can use fetch row and split it as well
mysql_fetch_field_row(orgstr, "orgid"); orgsid = strval(orgstr);
mysql_fetch_field_row(orgsname, "Name");
mysql_fetch_field_row(lname, "Leader");
format(orgstr, sizeof(orgstr), "Organization ID: %d || Organization Name: %s || Organization Leader: %s",orgsid,orgsname,lname);
SendClientMessage(playerid,-1,str);
}
mysql_free_result();
return 1;
}
Give that a go. If I have made an error, just correct it
.
Re: mysql problem -
Tanush123 - 17.12.2011
Wow. Well i have 2 orgs i just created, org id 0 and org id 1.
When i do /orgs while there is only org id 0 created it shows there is no orgs created.
When i do /orgs while there is org id 0 and 1 created it shows org id 1 two times
please help