Threaded query problem
#1

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?
Reply
#2

Guys please, it's urgent.
Reply
#3

Bump
Reply
#4

PHP код:
cache_get_data(rowsfieldsg_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"sahipIsimg_iHandlesizeof(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"sahipIsimg_iHandlesizeof(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"sahipIsimg_iHandlesizeof(sahipIsim)); 
Reply
#5

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
PHP код:
cache_get_data(rowsfieldsg_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"sahipIsimg_iHandlesizeof(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"sahipIsimg_iHandlesizeof(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"sahipIsimg_iHandlesizeof(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.
Reply
#6

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?
Reply
#7

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.
Reply
#8

@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(rowsfieldsg_iHandle);
    
cache_get_field_content(0"Character"sahipIsimg_iHandlesizeof(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;

Reply
#9

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(rowsfieldsg_iHandle);
    
cache_get_field_content(0"Character"sahipIsimg_iHandlesizeof(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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)