LoadHouses
#1

My function loadhouses
PHP код:
function LoadHouses()
{
    new 
query[200];
    new 
rowsfields
    
cache_get_data(rowsfieldsmysql);
    if(
rows
    {     
        for (new 
1MAX_HOUSESi++)
        {
            
mysql_format(mysql,query,sizeof(query),"SELECT * FROM `houses` WHERE `hID` = %d",i);
            
mysql_tquery(mysql,query);
            
HouseInfo[i][XEnt] = cache_get_field_content_float(0"XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
            
HouseInfo[i][YEnt] = cache_get_field_content_float(0"YEnt"); //Above
            
HouseInfo[i][ZEnt] = cache_get_field_content_float(0"ZEnt");//Above
            
HouseInfo[i][XExit] = cache_get_field_content_float(0"XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
            
HouseInfo[i][YExit] = cache_get_field_content_float(0"YExit");//Above
            
HouseInfo[i][ZExit] = cache_get_field_content_float(0"ZExit");//Above
            
HouseInfo[i][HVirtualWorld] = cache_get_field_content_int(0"HVirtualWorld");
            
HouseInfo[i][HInterior] = cache_get_field_content_int(0"HInterior");
            
HouseInfo[i][HPrice] = cache_get_field_content_int(0"HPrice");
            
cache_get_field_content(0,"HOwnerID",HouseInfo[i][HOwnerID], 24);
            
HouseInfo[i][HOwned] = cache_get_field_content_int(0"HOwned");
            
HouseInfo[i][HLocked] = cache_get_field_content_int(0"HLocked");
            
cache_get_field_content(0"HName"HouseInfo[i][HName], 30);
            
        }
        print(
"Successfully Loaded All Houses!");
    }
    else if(!
rows)
    {
        print(
"There are no houses to load!");
    }
    return 
1;

Even if i have already created a house and correctly have inserted a row with house info in my database it says there are no houses to load! any idea?
Reply
#2

If you add the code below before if(rows), will it always say 0 rows?
PHP код:
printf("houses: %d rows",rows); 
Have you made sure the mysql connection is working?
Reply
#3

Quote:
Originally Posted by CmZxC
Посмотреть сообщение
If you add the code below before if(rows), will it always say 0 rows?
PHP код:
printf("houses: %d rows",rows); 
Have you made sure the mysql connection is working?
it does work since my login register system in the gamemode works smoothly.
Let me give a print test for rows!
Reply
#4

When i create the first house it pass it to House ID 1 instead of 0? would that be a problem?
also
i truncated the table and recreated a house and it is inserted in table here it is when i restart sa-mp.exe it still says there are no rows!
Here isa picture of my table with the inserted row!
EDIT:Sorry for double post
Reply
#5

EDIT: reading this again i might be wrong.

You're possibly using a wrong function for your query.
swap
PHP код:
mysql_tquery 
with
PHP код:
mysql_query 
Are you also using tquery for your login system?
Reply
#6



show save function
Reply
#7

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение


show save function
Basicly i have created a createhouse function because i want to make the houses in-game and not by script so admins can add new in-game houses if they want.
so here is my createhouse function
PHP код:
function CreateHouse(Float:Xen,Float:Yen,Float:Zen,Float:Xex,Float:Yex,Float:Zex,virtualworld,interiorid,price)
{
        static 
hCount;
    new 
hid hCounthCount += 1;
    new 
string[100];
    new 
query[350];
    
hid += 1;
    
HouseInfo[hid][XEnt] = Xen;
    
HouseInfo[hid][YEnt] = Yen;
    
HouseInfo[hid][ZEnt] = Zen;
    
HouseInfo[hid][XExit] = Xex;
    
HouseInfo[hid][YExit] = Yex;
    
HouseInfo[hid][ZExit] = Zex;
    
HouseInfo[hid][HVirtualWorld] = virtualworld;
    
HouseInfo[hid][HInterior] = interiorid;
    
HouseInfo[hid][HPrice] = price;
    
HouseInfo[hid][HOwned] = 0;
    
HouseInfo[hid][HLocked] = 0;
    
format(string,sizeof(string),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",price);
    
HouseInfo[hid][H3D] = CreateDynamic3DTextLabel(stringCOLOR_YELLOWXen,  Yen,  Zen40.01);
    
mysql_format(mysql,query,sizeof(query), "INSERT INTO `houses` (`Xent`, `Yent`, `Zent`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld`, `HInterior`, `HPrice`,\
    `HOwned`, `HLocked`) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, 0, 0)"
Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
       
mysql_tquery(mysqlquery"RegisterHouse","i",hid); 
    return 
1;

Quote:
Originally Posted by CmZxC
Посмотреть сообщение
EDIT: reading this again i might be wrong.

You're possibly using a wrong function for your query.
swap
PHP код:
mysql_tquery 
with
PHP код:
mysql_query 
Are you also using tquery for your login system?
Yes but i call a different function named accountcheck should i change it to mysql_query?
Reply
#8

EDIT: nvm
Reply
#9

try this, and create new house
PHP код:
mysql_format(mysql,query,sizeof(query), "INSERT INTO `houses` (`Xent`, `Yent`, `Zent`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld`, `HInterior`, `HPrice`,\ 
`HOwned`, `HLocked`) VALUES (%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %d, %d, %d, 0, 0)"
Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price); 
mysql_tquery(mysqlquery"RegisterHouse","i",hid); 
https://sampwiki.blast.hk/wiki/Format
Reply
#10

Also check whether the `Xent`, `Yent`, `Zent`, `XExit`, `YExit`, `ZExit` in the SQL they are float
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)