Threaded query problem -
WhoIsYourDaddy - 25.02.2016
Hi guys, I have a problem. See, I want to get the house's owner name by searching houseOwner's ID in 'characters' table but just couldn't do it.
Here's my code:
Код:
forward evSahip(evID); // testing
public evSahip(evID)
{
new
rows,
fields,
sahipIsim[24];
cache_get_data(rows, fields, g_iHandle);
cache_get_field_content(rows, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
strpack(HouseData[evID][houseOwner], sahipIsim, 24 char);
return 1;
}
stock evSahipIsim(evID)
{
static
query[128],
evSahipID;
evSahipID = HouseData[evID][houseOwner];
format(query, sizeof(query), "SELECT `Character` FROM `characters` WHERE `ID` = '%d'", evSahipID);
mysql_tquery(g_iHandle, query, "evSahip", "d", evID);
return 1;
}
It always returns a null value. Where is the problem?
Re: Threaded query problem -
WhoIsYourDaddy - 25.02.2016
Guys please, it's urgent.
Re: Threaded query problem -
WhoIsYourDaddy - 25.02.2016
Bump
Re: Threaded query problem -
AmigaBlizzard - 25.02.2016
PHP код:
cache_get_data(rows, fields, g_iHandle);
This returns the amount of rows and fields. If you have 1 row returned, rows will be 1.
PHP код:
cache_get_field_content(rows, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
In case of 1 row returned, you use "rows" here to indicate the row to be processed.
But the first row in a result-set is row 0.
You're processing a non-existing row.
PHP код:
cache_get_field_content(rows - 1, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
Or better yet, if you're certain you only have 1 character to be returned (always 1 row):
PHP код:
cache_get_field_content(0, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
Re: Threaded query problem -
WhoIsYourDaddy - 26.02.2016
Quote:
Originally Posted by AmigaBlizzard
PHP код:
cache_get_data(rows, fields, g_iHandle);
This returns the amount of rows and fields. If you have 1 row returned, rows will be 1.
PHP код:
cache_get_field_content(rows, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
In case of 1 row returned, you use "rows" here to indicate the row to be processed.
But the first row in a result-set is row 0.
You're processing a non-existing row.
PHP код:
cache_get_field_content(rows - 1, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
Or better yet, if you're certain you only have 1 character to be returned (always 1 row):
PHP код:
cache_get_field_content(0, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
|
I see. But can you help me with getting the owner's name? It's south central mode. I just couldn't do it as you saw.
Re: Threaded query problem -
Jefff - 26.02.2016
1. evSahipID = HouseData[evID][houseOwner]; its integer array?
2. cache_get_field_content(rows, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim)); all what you need is replace 'rows' to 0
3. strpack(HouseData[evID][houseOwner], sahipIsim, 24 char); so its string not integer?
Re: Threaded query problem -
WhoIsYourDaddy - 26.02.2016
Quote:
Originally Posted by Jefff
1. evSahipID = HouseData[evID][houseOwner]; its integer array?
2. cache_get_field_content(rows, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim)); all what you need is replace 'rows' to 0
3. strpack(HouseData[evID][houseOwner], sahipIsim, 24 char); so its string not integer?
|
1. Yes, houseOwner is an integer. It keeps house owner's ID.
2. I don't know what I did there. It is a result of hours of desperate work, sadly...
3. I tried to find user's ID in 'houses' table and search it in 'characters' and find the owner's name. Didn't quite do it.
So here's the deal. House's and business's owners are saved by their SQLID not by name. And I want to get the owner's name using these IDs. It's South Central gamemode if you want to look at it. Obviously I can't do it by myself.
Re: Threaded query problem -
Virtual1ty - 26.02.2016
@OP
AmigaBlizzard and Jefff have already pointed you where your problem is.
The evSahipIsim() part is correct, your evSahip() "callback" is not.
PHP код:
forward evSahip(evID);
public evSahip(evID)
{
new
rows,
fields,
sahipIsim[24];
cache_get_data(rows, fields, g_iHandle);
cache_get_field_content(0, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
// strpack(HouseData[evID][houseOwner], sahipIsim, 24 char);
// ^ you cannot magically store a string to an integer variable
// do what you need with the house owner
// stored as a string in "sahipIsim" array
return 1;
}
Re: Threaded query problem -
WhoIsYourDaddy - 26.02.2016
Quote:
Originally Posted by Virtual1ty
@OP
AmigaBlizzard and Jefff have already pointed you where your problem is.
The evSahipIsim() part is correct, your evSahip() "callback" is not.
PHP код:
forward evSahip(evID);
public evSahip(evID)
{
new
rows,
fields,
sahipIsim[24];
cache_get_data(rows, fields, g_iHandle);
cache_get_field_content(0, "Character", sahipIsim, g_iHandle, sizeof(sahipIsim));
// strpack(HouseData[evID][houseOwner], sahipIsim, 24 char);
// ^ you cannot magically store a string to an integer variable
// do what you need with the house owner
// stored as a string in "sahipIsim" array
return 1;
}
|
Should the row for cache_get_field_content be 0? And can I return the string to get the name in different part of script.
Re: Threaded query problem -
Virtual1ty - 26.02.2016
Yes it should be as row index starts with 0.
No, you cannot return anything with threaded queries. Instead, you must restructure your code.
However, there's this neat little thing called "inline queries" with y_inline:
link.