SA-MP Forums Archive
MySQL LoadHouse - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL LoadHouse (/showthread.php?tid=394985)



MySQL LoadHouse - Fernado Samuel - 24.11.2012

Removed


Re: MySQL LoadHouse - Peach - 24.11.2012

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


Re: MySQL LoadHouse - Fernado Samuel - 24.11.2012

Removed


Re: MySQL LoadHouse - Peach - 24.11.2012

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

PHP код:
stock LoadHouses()
{
    new 
rowsidx 1string[256], query[256], query2[200], lines;
    
format(querysizeof(query), "SELECT * FROM houses");
    
mysql_query(query);
    
mysql_store_result();
    
lines mysql_num_rows();
    
mysql_free_result();
    for(new 
1linesi++)
    {
        
format(query2sizeof(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(12731HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ], 0);
              if(!
strcmp("trapstar2020"HouseInfo[i][hOwner]))
              {
                 
format(stringsizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d"iHouseInfo[i][hOwner], HouseInfo[i][hPrice]);
            }
             else 
format(stringsizeof(string), "ID: %d\nOwner: %s\nStatus: %s"i,  HouseInfo[i][hOwner], hlock(i));
             {
                
HouseInfo[i][hText] = CreateDynamic3DTextLabel(stringCOLOR_PURPLEHouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]+0.315);
               }
            
idx++;
            
mysql_free_result();
           }
           
printf("[Script] %d Houses were loaded."idx);
    }
    return 
1;




Re: MySQL LoadHouse - Fernado Samuel - 24.11.2012

Removed


Re: MySQL LoadHouse - ReneG - 24.11.2012

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 
rowsidx 1string[256], query[256], query2[200], lines;
    
format(querysizeof(query), "SELECT * FROM houses");
    
mysql_query(query);
    
mysql_store_result();
    
lines mysql_num_rows();
    
mysql_free_result();
    for(new 
1linesi++)
    {
        
format(query2sizeof(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(12731HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ], 0);
              if(!
strcmp("trapstar2020"HouseInfo[i][hOwner]))
              {
                 
format(stringsizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d"iHouseInfo[i][hOwner], HouseInfo[i][hPrice]);
            }
             else 
format(stringsizeof(string), "ID: %d\nOwner: %s\nStatus: %s"i,  HouseInfo[i][hOwner], hlock(i));
             {
                
HouseInfo[i][hText] = CreateDynamic3DTextLabel(stringCOLOR_PURPLEHouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]+0.315);
               }
            
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.


Re: MySQL LoadHouse - Peach - 24.11.2012

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.


Re: MySQL LoadHouse - Fernado Samuel - 25.11.2012

Removed