26.07.2016, 12:58
Quote:
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).
|
And ye there is a auto increment.
PHP код:
forward LoadHouses();
public LoadHouses()
{
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
{
new housepw[4], housetitle[MAX_HOUSE_NAME];
for(new i = 0; i < cache_get_row_count(); i++)
{
hInfo[i][hID] = cache_get_row_int(i, 0);
cache_get_row(i, 2, housetitle);
cache_get_row(i, 3, housepw);
hInfo[hInfo[i][hID]][hOwner] = cache_get_row_int(i, 1);
hInfo[hInfo[i][hID]][hInterior] = cache_get_row_int(i, 10);
hInfo[hInfo[i][hID]][hPrice] = cache_get_row_int(i, 11);
hInfo[hInfo[i][hID]][hEnterX] = cache_get_row_float(i, 4);
hInfo[hInfo[i][hID]][hEnterY] = cache_get_row_float(i, 5);
hInfo[hInfo[i][hID]][hEnterZ] = cache_get_row_float(i, 6);
hInfo[hInfo[i][hID]][hExitX] = cache_get_row_float(i, 7);
hInfo[hInfo[i][hID]][hExitY] = cache_get_row_float(i, 8);
hInfo[hInfo[i][hID]][hExitZ] = cache_get_row_float(i, 9);
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(hEntStr, sizeof(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(hEntStr, sizeof(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, -1, hInfo[hInfo[i][hID]][hEnterX], hInfo[hInfo[i][hID]][hEnterY], hInfo[hInfo[i][hID]][hEnterZ], 20.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, 0, -1, 100.0);
hInfo[hInfo[i][hID]][sExitLabel] = CreateDynamic3DTextLabel(""COL_GOLD"[EXIT]", -1, hInfo[hInfo[i][hID]][hExitX], hInfo[hInfo[i][hID]][hExitY], hInfo[hInfo[i][hID]][hExitZ], 20.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, hInfo[hInfo[i][hID]][hWorldID], hInfo[hInfo[i][hID]][hInterior], -1, 100.0);
hInfo[hInfo[i][hID]][hEnterCP] = CreateDynamicCP(hInfo[hInfo[i][hID]][hEnterX], hInfo[hInfo[i][hID]][hEnterY], hInfo[hInfo[i][hID]][hEnterZ], 1.0, -1, 0, -1, 100.0);
hInfo[hInfo[i][hID]][hExitCP] = CreateDynamicCP(hInfo[hInfo[i][hID]][hExitX], hInfo[hInfo[i][hID]][hExitY], hInfo[hInfo[i][hID]][hExitZ], 1.0, hInfo[hInfo[i][hID]][hWorldID], hInfo[hInfo[i][hID]][hInterior], -1, 100.0);
LoadedHouses++;
}
printf("Loaded %d houses", LoadedHouses);
}
else if(!rows)
{
printf("There are NO houses to load");
}
return 1;
}