• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Database query result question.

desalib

New Member
Joined
Jul 4, 2010
Messages
30
Reaction score
0
I added few lines in iologindata.cpp to add a variable player->customvar and It worked really well, I was able to retrieve it as planned.
The problem is that I'm not able to browse the result of a query when it is a list.

This is the code I came up with. What I want is to get the position of a result in the sorted list.

It's supposed to check if the player is in the top 5 of experience if yes tempvar = the position if no = 0.

Code:
result->free();
query.str("");

query << "SELECT `id`, `group_id`, `experience`, `level` "
<< "FROM `players` "
<< "WHERE `group_id` < 4 AND `deleted` = 0 "
<< "LIMIT 5  "
<< "ORDER BY `experience` DESC";


if((result = db->storeQuery(query.str()))) // Will it works to store an array of result? (knowing that result is declared this way "DBResult* result;"
		{
                            int tempvar =0;
                            //get the position in the result array where id = player->getGUID (or another way to retrieve actual player id)
                            //if not present left the value to 0
                }
 
I don't know what are you trying to do but this might help you :p

Code:
	DBQuery query;
	query << "SELECT `id` FROM `players` WHERE `group_id` < 4 AND `deleted` = 0 ORDER BY `experience` DESC LIMIT 5";
	DBResult* result;
	if(!(result = db->storeQuery(query.str())))
		return false;
	int tempvar =0;
	do
	{
		if(player->getGUID() == result->getDataInt("id"))
		{
			tempvar = player->getGUID();
			break;
		}
	}
	while(result->next());
	result->free();
 
Yeah it's hard to understand what I need sorry : )
But you clearly answered my question on how to use this query with an array of result ^^

Rep++
 
Back
Top