Why doesn't this work? (MySQL)
#1

pawn Код:
public OnGameModeInit()
{
    new query[128], classid[8];
    format(query, sizeof(query),"SELECT * FROM passwords WHERE class = '%s'", classid);
    mysql_query(query);
    mysql_store_result();
   
    while(mysql_fetch_row_format(query,"|"))
    {
        new tablevalue[16];
        strpack(classid, "l1a"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L1A, tablevalue);
        strpack(classid, "l2a"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L2A, tablevalue);
        strpack(classid, "l3s"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L3S, tablevalue);
        strpack(classid, "l4r"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L4R, tablevalue);
        strpack(classid, "l5m"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L5M, tablevalue);
        strpack(classid, "lvpd"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_LVPD, tablevalue);
    }
    mysql_free_result();

    return 1;
}
Seems like it should work to me.
Reply
#2

bump
Reply
#3

  • classid represents an array of integers, why are you using '%s' and why are you not refering to an index of the array anywhere?
  • The array classid is still empty at the point you are using it to format your query.
Reply
#4

Quote:
Originally Posted by Campbell-
Посмотреть сообщение
  • classid represents an array of integers, why are you using '%s' and why are you not refering to an index of the array anywhere?
  • The array classid is still empty at the point you are using it to format your query.
Then can you re-arrange it for me so it will work? I'm out of ideas on this.
Reply
#5

First of all you will have to define what the array classid should represent/what content it should carry. It's impossible to help you any further without knowing that.
Reply
#6

Re-arrange it how? You only need to change the "%s" to "%d" and define your classid to actually be something.
Reply
#7

Quote:
Originally Posted by Campbell-
Посмотреть сообщение
First of all you will have to define what the array classid should represent/what content it should carry. It's impossible to help you any further without knowing that.
classid represents these
pawn Код:
strpack(classid, "l1a");
        strpack(classid, "l2a");
        strpack(classid, "l3s");
        strpack(classid, "l4r");
        strpack(classid, "l5m");
        strpack(classid, "lvpd");
..or is that not what you're looking for?
Reply
#8

I think he means that classid doenst have a value, because every time a variable is declared in PAWN they values are set to zero, in case of arrays they are '\0' (null) so for the variable classid you have to asign an string because the current query you are running is:
pawn Код:
SELECT * FROM passwords WHERE class = ' '
(of course in run-time)
Reply
#9

I fixed it by forming it into a function:
pawn Код:
stock GetPassword(classid[], password[])
{
    new query[128], classstring[8];
    format(query, sizeof(query),"SELECT * FROM `passwords` WHERE `class` = '%s'", classid);
    mysql_query(query);
    mysql_store_result();

    while(mysql_fetch_row_format(query,"|"))
    {
        new tablevalue[16];
        strpack(classstring, classid); mysql_fetch_field_row(tablevalue, "password"); format(password, 16, "%s", tablevalue);
    }
    mysql_free_result();

    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)