GetFreeHouseID Mysql
#1

Hello,

I have a problem with my mysql house system.
I am trying to get the next free house id.
But when i use this stock its returning -1 while its needs to return 2 because i am already have houseid 1 in the database.
Код:
stock GetFreeHouseID()
{
    for(new h = 0; h < MAX_HOUSES; h++)
    {
		new query[128];
		format(query, sizeof(query), "SELECT * FROM `"#MYSQL_HOUSE_TABLE2"` WHERE `HouseID` = '%d'", h);
		mysql_store_result();
		if(mysql_num_rows(gSQL) == 0)
		{
			return h;
		}
        mysql_free_result();
	}
	return -1;
}
How can i fix this?

Admigo
Reply
#2

This won't help here, but you should be using threaded queries.
Reply
#3

Don't use the WHERE clause and neither the loop so it can select all the rows and then get the rows with the function is used for that.

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
This won't help here, but you should be using threaded queries.
It's indeed better of using threaded queries.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Don't use the WHERE clause and neither the loop so it can select all the rows and then get the rows with the function is used for that.



It's indeed better of using threaded queries.
Okay thanks for the information. I will use threaded queries.
Reply
#5

Use house arrays for this, example

pawn Код:
stock GetFreeHouseID()
{
    for(new h = 0; h < MAX_HOUSES; h++)
    {
        if(HouseInfo[h][hID] == 0) // or if house is not owned
            return h;
    }
    return -1;
}
or load in OnGameModeInit all houses and set
HousesInGame = LoadedHouses;

and your free slot is HousesInGame
pawn Код:
HouseInfo[HousesInGame][hID] = HousesInGame;
rest house arrays
...
...
HousesInGame++;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)