MySQL LoadHouse
#1

Removed
Reply
#2

First of all you'd need to create the table and are you sure your script is even running MySQL?
Reply
#3

Removed
Reply
#4

100% untested but if you know the basis on MySQL this should be easy for you.

PHP код:
stock LoadHouses()
{
    new 
rows, idx = 1, string[256], query[256], query2[200], lines;
    
format(query, sizeof(query), "SELECT * FROM houses");
    
mysql_query(query);
    
mysql_store_result();
    
lines = mysql_num_rows();
    
mysql_free_result();
    for(new 
i = 1; i < lines; i++)
    {
        
format(query2, sizeof(query2), "SELECT * FROM houses WHERE id = %i", i);
        
mysql_query(query2);
        
mysql_store_result();
        while(
mysql_fetch_row_format(query2, "|"))
        {
            
mysql_fetch_field_row(HouseInfo[i][hPrice], "houseprice");
             
mysql_fetch_field_row(HouseInfo[i][hStatus], "housestatus");
             
mysql_fetch_field_row(HouseInfo[i][hOwner], "houseowner");
             
mysql_fetch_field_row(HouseInfo[i][hX], "housex");
             
mysql_fetch_field_row(HouseInfo[i][hY], "housey");
             
mysql_fetch_field_row(HouseInfo[i][hZ], "housez");
             
             
HouseInfo[i][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ], 0);
              if(!
strcmp("trapstar2020", HouseInfo[i][hOwner]))
              {
                 
format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d", i, HouseInfo[i][hOwner], HouseInfo[i][hPrice]);
            }
             else 
format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: %s", i,  HouseInfo[i][hOwner], hlock(i));
             {
                
HouseInfo[i][hText] = CreateDynamic3DTextLabel(string, COLOR_PURPLE, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]+0.3, 15);
               }
            
idx++;
            
mysql_free_result();
           }
           
printf("[Script] %d Houses were loaded.", idx);
    }
    return 
1;
} 
Reply
#5

Removed
Reply
#6

Quote:
Originally Posted by Peach
Посмотреть сообщение
100% untested but if you know the basis on MySQL this should be easy for you.

PHP код:
stock LoadHouses()
{
    new 
rows, idx = 1, string[256], query[256], query2[200], lines;
    
format(query, sizeof(query), "SELECT * FROM houses");
    
mysql_query(query);
    
mysql_store_result();
    
lines = mysql_num_rows();
    
mysql_free_result();
    for(new 
i = 1; i < lines; i++)
    {
        
format(query2, sizeof(query2), "SELECT * FROM houses WHERE id = %i", i);
        
mysql_query(query2);
        
mysql_store_result();
        while(
mysql_fetch_row_format(query2, "|"))
        {
            
mysql_fetch_field_row(HouseInfo[i][hPrice], "houseprice");
             
mysql_fetch_field_row(HouseInfo[i][hStatus], "housestatus");
             
mysql_fetch_field_row(HouseInfo[i][hOwner], "houseowner");
             
mysql_fetch_field_row(HouseInfo[i][hX], "housex");
             
mysql_fetch_field_row(HouseInfo[i][hY], "housey");
             
mysql_fetch_field_row(HouseInfo[i][hZ], "housez");
             
             
HouseInfo[i][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ], 0);
              if(!
strcmp("trapstar2020", HouseInfo[i][hOwner]))
              {
                 
format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d", i, HouseInfo[i][hOwner], HouseInfo[i][hPrice]);
            }
             else 
format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: %s", i,  HouseInfo[i][hOwner], hlock(i));
             {
                
HouseInfo[i][hText] = CreateDynamic3DTextLabel(string, COLOR_PURPLE, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]+0.3, 15);
               }
            
idx++;
            
mysql_free_result();
           }
           
printf("[Script] %d Houses were loaded.", idx);
    }
    return 
1;
} 
That's not the right way to fetch a result set from a MySQL table. You first select all of the records, and then run a query to fetch each record? It is more practical to fetch all of the records and then loop through them, storing the data into server memory.
Reply
#7

Ah I see what you mean. I see what I did wrong, thanks for pointing that out. I load my houses differently to this so it was harder for me to do it this way.
Reply
#8

Removed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)