MySQL insert help
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
In mysql_tquery, specify a callback and in that callback use cache_insert_id to retrieve the unique ID (the column has to be set with auto increment). I can't say about the index (if you have variables for the house data at all) much as you didn't post any additional information but having a global variable that stores the number of loaded houses will come in handy, not only for the loops but it is the index of the next house (the house to be created).
Well, I got a variable "LoadedHouses", even it printf's how many houses were loaded when it finishes loading.
And ye there is a auto increment.

PHP код:
forward LoadHouses();
public 
LoadHouses()
{
    new 
rowsfields;
     
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        new 
housepw[4], housetitle[MAX_HOUSE_NAME];
        for(new 
0cache_get_row_count(); i++)
        {
            
hInfo[i][hID] = cache_get_row_int(i0);
            
cache_get_row(i2housetitle);
            
cache_get_row(i3housepw);
            
            
hInfo[hInfo[i][hID]][hOwner] = cache_get_row_int(i1);
            
hInfo[hInfo[i][hID]][hInterior] = cache_get_row_int(i10);
            
hInfo[hInfo[i][hID]][hPrice] = cache_get_row_int(i11);
            
hInfo[hInfo[i][hID]][hEnterX] = cache_get_row_float(i4);
            
hInfo[hInfo[i][hID]][hEnterY] = cache_get_row_float(i5);
            
hInfo[hInfo[i][hID]][hEnterZ] = cache_get_row_float(i6);
            
hInfo[hInfo[i][hID]][hExitX] = cache_get_row_float(i7);
            
hInfo[hInfo[i][hID]][hExitY] = cache_get_row_float(i8);
            
hInfo[hInfo[i][hID]][hExitZ] = cache_get_row_float(i9);
            
hInfo[hInfo[i][hID]][hTitle] = housetitle;
            
hInfo[hInfo[i][hID]][hPassword] = housepw;
            
hInfo[hInfo[i][hID]][hWorldID] = hInfo[i][hID];
            
            new 
hEntStr[200];
            if(
hInfo[hInfo[i][hID]][hOwner] == -1)
            {
                
format(hEntStrsizeof(hEntStr), ""COL_GOLD"House: "COL_WHITE"%s(%d)\n"COL_GOLD"Owner: "COL_WHITE"No-one\n"COL_GOLD"Price: "COL_WHITE"$%s"hInfo[hInfo[i][hID]][hTitle], hInfo[i][hID], AC(hInfo[hInfo[i][hID]][hPrice]));
            }
            if(
hInfo[hInfo[i][hID]][hOwner] != -1)
            {
                
format(hEntStrsizeof(hEntStr), ""COL_GOLD"House: "COL_WHITE"%s(%d)\n"COL_GOLD"Owner: "COL_WHITE"%s\n"COL_GOLD"Price: "COL_WHITE"$%s"hInfo[hInfo[i][hID]][hTitle], hInfo[i][hID], GetNameFromMySQLID(hInfo[hInfo[i][hID]][hOwner]), AC(hInfo[hInfo[i][hID]][hPrice]));
            }
            
hInfo[hInfo[i][hID]][sEnterLabel] = CreateDynamic3DTextLabel(hEntStr, -1hInfo[hInfo[i][hID]][hEnterX], hInfo[hInfo[i][hID]][hEnterY], hInfo[hInfo[i][hID]][hEnterZ], 20.0INVALID_PLAYER_IDINVALID_VEHICLE_ID1, -10, -1100.0);
            
hInfo[hInfo[i][hID]][sExitLabel] = CreateDynamic3DTextLabel(""COL_GOLD"[EXIT]", -1hInfo[hInfo[i][hID]][hExitX], hInfo[hInfo[i][hID]][hExitY], hInfo[hInfo[i][hID]][hExitZ], 20.0INVALID_PLAYER_IDINVALID_VEHICLE_ID1hInfo[hInfo[i][hID]][hWorldID], hInfo[hInfo[i][hID]][hInterior], -1100.0);
            
hInfo[hInfo[i][hID]][hEnterCP] = CreateDynamicCP(hInfo[hInfo[i][hID]][hEnterX], hInfo[hInfo[i][hID]][hEnterY], hInfo[hInfo[i][hID]][hEnterZ], 1.0, -10, -1100.0);
            
hInfo[hInfo[i][hID]][hExitCP] = CreateDynamicCP(hInfo[hInfo[i][hID]][hExitX], hInfo[hInfo[i][hID]][hExitY], hInfo[hInfo[i][hID]][hExitZ], 1.0hInfo[hInfo[i][hID]][hWorldID], hInfo[hInfo[i][hID]][hInterior], -1100.0);
               
LoadedHouses++;
        }
        
printf("Loaded %d houses"LoadedHouses);
    }
    else if(!
rows)
    {
        
printf("There are NO houses to load");
    }
    return 
1;

Reply


Messages In This Thread
MySQL insert help - by Ahmed21 - 26.07.2016, 12:47
Re: MySQL insert help - by Konstantinos - 26.07.2016, 12:54
Re: MySQL insert help - by Ahmed21 - 26.07.2016, 12:58
Re: MySQL insert help - by Konstantinos - 26.07.2016, 13:05
Re: MySQL insert help - by Ahmed21 - 26.07.2016, 13:26
Re: MySQL insert help - by Ahmed21 - 26.07.2016, 13:40
Re: MySQL insert help - by Konstantinos - 26.07.2016, 16:38
Re: MySQL insert help - by Ahmed21 - 26.07.2016, 16:59
Re: MySQL insert help - by Ahmed21 - 26.07.2016, 17:23
Re: MySQL insert help - by Konstantinos - 26.07.2016, 17:30

Forum Jump:


Users browsing this thread: 1 Guest(s)