Why doesn't this work? (MySQL) -
austin070 - 28.04.2014
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.
Re: Why doesn't this work? (MySQL) -
austin070 - 28.04.2014
bump
Re: Why doesn't this work? (MySQL) -
Campbell- - 28.04.2014
- 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.
Re: Why doesn't this work? (MySQL) -
austin070 - 28.04.2014
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.
Re: Why doesn't this work? (MySQL) -
Campbell- - 28.04.2014
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.
Re: Why doesn't this work? (MySQL) -
Dignity - 28.04.2014
Re-arrange it how? You only need to change the "%s" to "%d" and define your classid to actually be something.
Re: Why doesn't this work? (MySQL) -
austin070 - 28.04.2014
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?
Respuesta: Why doesn't this work? (MySQL) -
JustBored - 28.04.2014
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)
Re: Why doesn't this work? (MySQL) -
austin070 - 29.04.2014
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;
}