Help...Loading Groups
#1

pawn Код:
stock LoadGroup(id)
{
    new data[256];
    format(GlobalQuery1, sizeof(GlobalQuery1), "SELECT * FROM Groups WHERE Groupid = %d LIMIT 1",id);
    mysql_query(GlobalQuery1);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        new line[700];
        if(mysql_fetch_row(line,"|"))
        {
            new Gstr[9][70],Gvar[1];
            sscanf(line, "p<|>ds[255]s[255]s[255]s[255]s[255]s[255]s[255]s[255]s[255]",Gvar[0],Gstr[0],Gstr[1],Gstr[2],Gstr[3],Gstr[4],Gstr[5],Gstr[6],Gstr[7],Gstr[8]);
            Groups[id][Groupid] = Gvar[0];
            strmid(Groups[id][GroupName], Gstr[0], false, strlen(Groups[id][GroupName]), 255);
            strmid(Groups[id][RankName0], Gstr[1], false, strlen(Groups[id][RankName0]), 255);
            strmid(Groups[id][RankName1], Gstr[2], false, strlen(Groups[id][RankName1]), 255);
            strmid(Groups[id][RankName2], Gstr[3], false, strlen(Groups[id][RankName2]), 255);
            strmid(Groups[id][RankName3], Gstr[4], false, strlen(Groups[id][RankName3]), 255);
            strmid(Groups[id][RankName4], Gstr[5], false, strlen(Groups[id][RankName4]), 255);
            strmid(Groups[id][RankName5], Gstr[6], false, strlen(Groups[id][RankName5]), 255);
            strmid(Groups[id][RankName6], Gstr[7], false, strlen(Groups[id][RankName6]), 255);
            strmid(Groups[id][MOTD], Gstr[8], false, strlen(Groups[id][MOTD]), 255);
            printf("Loaded Groupid:%d",id);
            printf("Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
            Groups[id][Groupid],Groups[id][GroupName],Groups[id][RankName0],Groups[id][RankName1],Groups[id][RankName2],
            Groups[id][RankName3],Groups[id][RankName4],Groups[id][RankName5],Groups[id][RankName6],Groups[id][MOTD]);
        }
        GroupCount++;
        mysql_fetch_field("Groupid",data);
        Groups[id][Groupid]=strval(data);
        mysql_fetch_field("GroupName",data);
        strmid(Groups[id][GroupName], data, false, strlen(Groups[id][GroupName]), 255);
        mysql_fetch_field("RankName0",data);
        strmid(Groups[id][RankName0], data, false, strlen(Groups[id][RankName0]), 255);
        mysql_fetch_field("RankName1",data);
        strmid(Groups[id][RankName1], data, false, strlen(Groups[id][RankName1]), 255);
        mysql_fetch_field("RankName2",data);
        strmid(Groups[id][RankName2], data, false, strlen(Groups[id][RankName2]), 255);
        mysql_fetch_field("RankName3",data);
        strmid(Groups[id][RankName3], data, false, strlen(Groups[id][RankName3]), 255);
        mysql_fetch_field("RankName4",data);
        strmid(Groups[id][RankName4], data, false, strlen(Groups[id][RankName4]), 255);
        mysql_fetch_field("RankName5",data);
        strmid(Groups[id][RankName5], data, false, strlen(Groups[id][RankName5]), 255);
        mysql_fetch_field("RankName6",data);
        strmid(Groups[id][RankName6], data, false, strlen(Groups[id][RankName6]), 255);
        mysql_fetch_field("MOTD",data);
        strmid(Groups[id][MOTD], data, false, strlen(Groups[id][MOTD]), 255);
        printf("Loaded Groupid:%d",id);
        printf("Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
        Groups[id][Groupid],Groups[id][GroupName],Groups[id][RankName0],Groups[id][RankName1],Groups[id][RankName2],
        Groups[id][RankName3],Groups[id][RankName4],Groups[id][RankName5],Groups[id][RankName6],Groups[id][MOTD]);
    }
    mysql_free_result();
    return 1;
}
prints
pawn Код:
[17:25:30] Loaded Groupid:1
[17:25:30] Groupid:1 Name: Rank0: Rank1: Rank2: Rank3: Rank4: Rank5: Rank6: MOTD:
[17:25:30] Loaded Groupid:1
[17:25:30] Groupid:1 Name: Rank0: Rank1: Rank2: Rank3: Rank4: Rank5: Rank6: MOTD:
with the both ways-.-

pawn Код:
[Tue Nov 23 17:25:30 2010] Function: mysql_query executed: "SELECT * FROM Groups WHERE Groupid = 1 LIMIT 1" with result: "0".
[Tue Nov 23 17:25:30 2010] Function: mysql_store_result executed with result: "1"
[Tue Nov 23 17:25:30 2010] Function: mysql_num_rows executed with result: "%".
[Tue Nov 23 17:25:30 2010] Function: mysql_fetch_row executed with result: "1|Timeless|Newbie|Big Newbie|Hawt Newbie|Sexy Newbie|Pro|Expert Wanker|Leader|Welcome Back Timeless Killers".
Reply
#2

What's with all the strmid balls? Why not just use something like this......

pawn Код:
while(mysql_fetch_row(line)==1)
    {
        mysql_fetch_field_row(field, "Skin1");
        gSkinSets[count][0] = strval(field);
        mysql_fetch_field_row(field, "Skin2");
        gSkinSets[count][1] = strval(field);
        mysql_fetch_field_row(field, "Skin3");
        gSkinSets[count][2] = strval(field);
        mysql_fetch_field_row(field, "SetCost");
        gSkinSets[count][4] = strval(field);
    }
Reply
#3

strmid cus its a string also i did use mysql_fetch_field("RankName3",data); just incase the if(mysql_fetch_row(line,"|")) part didnt work
Reply
#4

Why bother doing it your way in the first place? mysql_fetch_field is much easier, and doesn't require adjusting a heap of code if your table structure changes order.

You are making things hard on yourself unnecessarily.
Reply
#5

i did it both ways to test.. but none are working so i just left the code how it is
Reply
#6

if(mysql_fetch_row(line))

...maybe...
Reply
#7

tried that to
Reply
#8

Did you remove the sscanf to use the mysql_fetch_field_row?
Reply
#9

still doesnt work
Reply
#10

Post your code. Can't help you on a "Still doesn't work" comment.
Reply
#11

pawn Код:
stock LoadGroups2()
{
    printf("[System] Loading Groups's....");
    new data[256];
    for (new i=0; i<MAX_GROUPS; i++)
    {
        format(GlobalQuery, sizeof(GlobalQuery), "SELECT * FROM Groups ORDER BY Groupid");
        mysql_query(GlobalQuery);
        mysql_store_result();
        if(mysql_num_rows() > 0)
        {
            new line[1024];
            while(mysql_fetch_row(line)==1)
            {
                GroupCount++;
                mysql_fetch_field_row(data,"Groupid");
                Groups[i][Groupid]=strval(data);
                mysql_fetch_field_row(data,"GroupName");
                strmid(Groups[i][GroupName], data, false, strlen(Groups[i][GroupName]), 255);
                mysql_fetch_field_row(data,"RankName0");
                strmid(Groups[i][RankName0], data, false, strlen(Groups[i][RankName0]), 255);
                mysql_fetch_field_row(data,"RankName1");
                strmid(Groups[i][RankName1], data, false, strlen(Groups[i][RankName1]), 255);
                mysql_fetch_field_row(data,"RankName2");
                strmid(Groups[i][RankName2], data, false, strlen(Groups[i][RankName2]), 255);
                mysql_fetch_field_row(data,"RankName3");
                strmid(Groups[i][RankName3], data, false, strlen(Groups[i][RankName3]), 255);
                mysql_fetch_field_row(data,"RankName4");
                strmid(Groups[i][RankName4], data, false, strlen(Groups[i][RankName4]), 255);
                mysql_fetch_field_row(data,"RankName5");
                strmid(Groups[i][RankName5], data, false, strlen(Groups[i][RankName5]), 255);
                mysql_fetch_field_row(data,"RankName6");
                strmid(Groups[i][RankName6], data, false, strlen(Groups[i][RankName6]), 255);
                mysql_fetch_field_row(data,"MOTD);
                strmid(Groups[i][MOTD], data, false, strlen(Groups[i][MOTD]), 255);
                printf("
Loaded Groupid:%d",id);
                printf("
Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
                Groups[i][Groupid],Groups[i][GroupName],Groups[i][RankName0],Groups[i][RankName1],Groups[i][RankName2],
                Groups[i][RankName3],Groups[i][RankName4],Groups[i][RankName5],Groups[i][RankName6],Groups[i][MOTD]);
            }
        }
    }
    printf("
[System] A Total Of %d Groups Spawned!",GroupCount);
    mysql_free_result();
    return 1;
}
o i hjust realized thats not a function.. btw.. im using stricken kids plugin, it doesnt have mysql_fetch_field_row
Reply
#12

Convert to gStylez plugin. I don't even think you actually have to change ANYTHING, it should work.

pawn Код:
stock LoadGroups2()
{
    printf("[System] Loading Groups's....");
    new data[256], i;
    format(GlobalQuery, sizeof(GlobalQuery), "SELECT * FROM Groups ORDER BY Groupid");
    mysql_query(GlobalQuery);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        new line[1024];
        while(mysql_fetch_row(line)==1)
        {
            i = GroupCount;
            mysql_fetch_field_row(data,"Groupid");
            Groups[i][Groupid]=strval(data);
            mysql_fetch_field_row(data,"GroupName");
            strmid(Groups[i][GroupName], data, false, strlen(Groups[i][GroupName]), 255);
            mysql_fetch_field_row(data,"RankName0");
            strmid(Groups[i][RankName0], data, false, strlen(Groups[i][RankName0]), 255);
            mysql_fetch_field_row(data,"RankName1");
            strmid(Groups[i][RankName1], data, false, strlen(Groups[i][RankName1]), 255);
            mysql_fetch_field_row(data,"RankName2");
            strmid(Groups[i][RankName2], data, false, strlen(Groups[i][RankName2]), 255);
            mysql_fetch_field_row(data,"RankName3");
            strmid(Groups[i][RankName3], data, false, strlen(Groups[i][RankName3]), 255);
            mysql_fetch_field_row(data,"RankName4");
            strmid(Groups[i][RankName4], data, false, strlen(Groups[i][RankName4]), 255);
            mysql_fetch_field_row(data,"RankName5");
            strmid(Groups[i][RankName5], data, false, strlen(Groups[i][RankName5]), 255);
            mysql_fetch_field_row(data,"RankName6");
            strmid(Groups[i][RankName6], data, false, strlen(Groups[i][RankName6]), 255);
            mysql_fetch_field_row(data,"MOTD);
            strmid(Groups[i][MOTD], data, false, strlen(Groups[i][MOTD]), 255);
            printf("
Loaded Groupid:%d",id);
            printf("
Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
            Groups[i][Groupid],Groups[i][GroupName],Groups[i][RankName0],Groups[i][RankName1],Groups[i][RankName2],
            Groups[i][RankName3],Groups[i][RankName4],Groups[i][RankName5],Groups[i][RankName6],Groups[i][MOTD]);
            GroupCount++;
        }
    }
    printf("
[System] A Total Of %d Groups Spawned!",GroupCount);
    mysql_free_result();
    return 1;
}
Reply
#13

1. converted to gstylezzz
2. it didn't load cus it only printed printf("[System] Loading Groups's....");
and this doesnt work either, even though i converted

pawn Код:
stock LoadGroup(id)
{
    new data[256];
    format(GlobalQuery1, sizeof(GlobalQuery1), "SELECT * FROM Groups WHERE Groupid = %d LIMIT 1",id);
    mysql_query(GlobalQuery1);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        new line[700];
        if(mysql_fetch_row(line))
        {
            new Gstr[9][70],Gvar[1];
            sscanf(line, "p<|>ds[255]s[255]s[255]s[255]s[255]s[255]s[255]s[255]s[255]",Gvar[0],Gstr[0],Gstr[1],Gstr[2],Gstr[3],Gstr[4],Gstr[5],Gstr[6],Gstr[7],Gstr[8]);
            Groups[id][Groupid] = Gvar[0];
            strmid(Groups[id][GroupName], Gstr[0], false, strlen(Groups[id][GroupName]), 255);
            strmid(Groups[id][RankName0], Gstr[1], false, strlen(Groups[id][RankName0]), 255);
            strmid(Groups[id][RankName1], Gstr[2], false, strlen(Groups[id][RankName1]), 255);
            strmid(Groups[id][RankName2], Gstr[3], false, strlen(Groups[id][RankName2]), 255);
            strmid(Groups[id][RankName3], Gstr[4], false, strlen(Groups[id][RankName3]), 255);
            strmid(Groups[id][RankName4], Gstr[5], false, strlen(Groups[id][RankName4]), 255);
            strmid(Groups[id][RankName5], Gstr[6], false, strlen(Groups[id][RankName5]), 255);
            strmid(Groups[id][RankName6], Gstr[7], false, strlen(Groups[id][RankName6]), 255);
            strmid(Groups[id][MOTD], Gstr[8], false, strlen(Groups[id][MOTD]), 255);
            printf("Loaded Groupid:%d",id);
            printf("Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
            Groups[id][Groupid],Groups[id][GroupName],Groups[id][RankName0],Groups[id][RankName1],Groups[id][RankName2],
            Groups[id][RankName3],Groups[id][RankName4],Groups[id][RankName5],Groups[id][RankName6],Groups[id][MOTD]);
        }
        GroupCount++;
        mysql_fetch_field_row("Groupid",data);
        Groups[id][Groupid]=strval(data);
        mysql_fetch_field_row("GroupName",data);
        strmid(Groups[id][GroupName], data, false, strlen(Groups[id][GroupName]), 255);
        mysql_fetch_field_row("RankName0",data);
        strmid(Groups[id][RankName0], data, false, strlen(Groups[id][RankName0]), 255);
        mysql_fetch_field_row("RankName1",data);
        strmid(Groups[id][RankName1], data, false, strlen(Groups[id][RankName1]), 255);
        mysql_fetch_field_row("RankName2",data);
        strmid(Groups[id][RankName2], data, false, strlen(Groups[id][RankName2]), 255);
        mysql_fetch_field_row("RankName3",data);
        strmid(Groups[id][RankName3], data, false, strlen(Groups[id][RankName3]), 255);
        mysql_fetch_field_row("RankName4",data);
        strmid(Groups[id][RankName4], data, false, strlen(Groups[id][RankName4]), 255);
        mysql_fetch_field_row("RankName5",data);
        strmid(Groups[id][RankName5], data, false, strlen(Groups[id][RankName5]), 255);
        mysql_fetch_field_row("RankName6",data);
        strmid(Groups[id][RankName6], data, false, strlen(Groups[id][RankName6]), 255);
        mysql_fetch_field_row("MOTD",data);
        strmid(Groups[id][MOTD], data, false, strlen(Groups[id][MOTD]), 255);
        printf("Loaded Groupid:%d",id);
        printf("Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
        Groups[id][Groupid],Groups[id][GroupName],Groups[id][RankName0],Groups[id][RankName1],Groups[id][RankName2],
        Groups[id][RankName3],Groups[id][RankName4],Groups[id][RankName5],Groups[id][RankName6],Groups[id][MOTD]);
    }
    mysql_free_result();
    return 1;
}
pawn Код:
stock LoadGroups2()
{
    printf("[System] Loading Groups's....");
    new data[256], i;
    format(GlobalQuery, sizeof(GlobalQuery), "SELECT * FROM Groups ORDER BY Groupid");
    mysql_query(GlobalQuery);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        new line[1024];
        while(mysql_fetch_row(line)==1)
        {
            GroupCount++;
            i = GroupCount;
            mysql_fetch_field_row(data,"Groupid");
            Groups[i][Groupid]=strval(data);
            mysql_fetch_field_row(data,"GroupName");
            strmid(Groups[i][GroupName], data, false, strlen(Groups[i][GroupName]), 255);
            mysql_fetch_field_row(data,"RankName0");
            strmid(Groups[i][RankName0], data, false, strlen(Groups[i][RankName0]), 255);
            mysql_fetch_field_row(data,"RankName1");
            strmid(Groups[i][RankName1], data, false, strlen(Groups[i][RankName1]), 255);
            mysql_fetch_field_row(data,"RankName2");
            strmid(Groups[i][RankName2], data, false, strlen(Groups[i][RankName2]), 255);
            mysql_fetch_field_row(data,"RankName3");
            strmid(Groups[i][RankName3], data, false, strlen(Groups[i][RankName3]), 255);
            mysql_fetch_field_row(data,"RankName4");
            strmid(Groups[i][RankName4], data, false, strlen(Groups[i][RankName4]), 255);
            mysql_fetch_field_row(data,"RankName5");
            strmid(Groups[i][RankName5], data, false, strlen(Groups[i][RankName5]), 255);
            mysql_fetch_field_row(data,"RankName6");
            strmid(Groups[i][RankName6], data, false, strlen(Groups[i][RankName6]), 255);
            mysql_fetch_field_row(data,"MOTD");
            strmid(Groups[i][MOTD], data, false, strlen(Groups[i][MOTD]), 255);
            printf("Loaded Groupid:%d",GroupCount);
            printf("Groupid:%d Name:%s Rank0:%s Rank1:%s Rank2:%s Rank3:%s Rank4:%s Rank5:%s Rank6:%s MOTD:%s",
            Groups[i][Groupid],Groups[i][GroupName],Groups[i][RankName0],Groups[i][RankName1],Groups[i][RankName2],
            Groups[i][RankName3],Groups[i][RankName4],Groups[i][RankName5],Groups[i][RankName6],Groups[i][MOTD]);
            GroupCount++;
        }
    }
    printf("[System] A Total Of %d Groups Spawned!",GroupCount);
    mysql_free_result();
    return 1;
}
Reply
#14

Perform "SELECT * FROM Groups WHERE Groupid = %d LIMIT 1" in phpMyAdmin or whatever interface you can and show me it works.
Reply
#15

pawn Код:
Error
SQL query:

SELECT *
FROM Groups
WHERE Groupid = % d
LIMIT 1

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%d LIMIT 1' at line 1
the %d Part?
Reply
#16

The %d would be a group number.

Do you have any records in the table? Use them as an example.
Reply
#17

ya it returned find when i used groupid = 1

there is 1 group in the table atm.
Reply
#18

Are the column names correct? For example is "GroupName" spelt with the same casing in the table?
Reply
#19

yep

Код:
Field	Type	Collation	Attributes	Null	Default	Extra	Action
	Groupid	int(11)			No			 	 	 	 	 	 	
	GroupName	text	latin1_swedish_ci		No			 	 	 				 
	RankName0	text	latin1_swedish_ci		No			 	 	 				 
	RankName1	text	latin1_swedish_ci		No			 	 	 				 
	RankName2	text	latin1_swedish_ci		No			 	 	 				 
	RankName3	text	latin1_swedish_ci		No			 	 	 				 
	RankName4	text	latin1_swedish_ci		No			 	 	 				 
	RankName5	text	latin1_swedish_ci		No			 	 	 				 
	RankName6	text	latin1_swedish_ci		No			 	 	 				 
	MOTD	text	latin1_swedish_ci		No
Reply
#20

Are any of the values printed right?

And what shows if you "printf("Line: %s", line);"?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)