LoadBusinesses() {
query[0] = 0;
format(query,sizeof(query),"SELECT `business`.`id`,`name`,`owner`,`c1`.`username`,`extortion`,`c2`.`username`,`EntranceX`,`EntranceY`,`EntranceZ`,`ExitX`,`ExitY`,`ExitZ`,`business`.`interior`,`type`,`value`,`locked`,`entrancefee`,`till`,`products`,`maxproducts` FROM `business` LEFT JOIN `characters` AS `c1` ON `business`.`owner` = `c1`.`id` LEFT JOIN `characters` AS `c2` ON `business`.`extortion` = `c2`.`id`");
mysql_function_query(g_mysql_handle, query, true, "onLoadBusiness", "");
}
public onLoadBusiness() {
new data[1728],id_val;
new Float:f_val;
new rows,fields;
cache_get_data(rows,fields);
printf("Number of businesses: %d\n", rows);
for(new index=0;index<rows;index++) {
new i = findFreeBusiness();
cache_get_row(index, 0, data); //business SQL id
id_val = strval(data);
Business[i][EBusinessID] = id_val;
cache_get_row(index, 1, data); //business name
format(Business[i][EBusinessName],64,"%s",data);
cache_get_row(index, 2, data); //owner SQL id
id_val = strval(data);
Business[i][EBusinessOwner] = id_val;
if(Business[i][EBusinessOwner] == 0) {
format(Business[i][EBusinessOwnerName],MAX_PLAYER_NAME,"No-One");
} else if(Business[i][EBusinessOwner] == -1) {
format(Business[i][EBusinessOwnerName],MAX_PLAYER_NAME,"The State");
} else {
cache_get_row(index, 3, data); //owner username
format(Business[i][EBusinessOwnerName],MAX_PLAYER_NAME,"%s",data);
}
cache_get_row(index, 4, data); //extortion
id_val = strval(data);
Business[i][EBusinessExtortionist] = id_val;
if(id_val != 0) {
cache_get_row(index, 5, data); //extortionist username
format(Business[i][EBusinessExtortionName],MAX_PLAYER_NAME,"%s",data);
}
cache_get_row(index, 6, data);
f_val = floatstr(data);
Business[i][EBusinessEntranceX] = f_val;
cache_get_row(index, 7, data);
f_val = floatstr(data);
Business[i][EBusinessEntranceY] = f_val;
cache_get_row(index, 8, data);
f_val = floatstr(data);
Business[i][EBusinessEntranceZ] = f_val;
cache_get_row(index, 9, data);
f_val = floatstr(data);
Business[i][EBusinessExitX] = f_val;
cache_get_row(index, 10, data);
f_val = floatstr(data);
Business[i][EBusinessExitY] = f_val;
cache_get_row(index, 11, data);
f_val = floatstr(data);
Business[i][EBusinessExitZ] = f_val;
cache_get_row(index, 12, data);
id_val = strval(data);
Business[i][EBusinessInterior] = id_val;
cache_get_row(index, 13, data);
id_val = strval(data);
Business[i][EBType] = EBusinessType:id_val;
cache_get_row(index, 14, data);
id_val = strval(data);
Business[i][EBusinessPrice] = id_val;
cache_get_row(index, 15, data);
id_val = strval(data);
Business[i][EBusinessLocked] = id_val;
Business[i][EBusinessVW] = i+BIZ_VW_OFFSET;
cache_get_row(index, 16, data);
id_val = strval(data);
Business[i][EBusinessEntranceFee] = id_val;
cache_get_row(index, 17, data);
id_val = strval(data);
Business[i][EBusinessTill] = id_val;
cache_get_row(index, 18, data);
id_val = strval(data);
Business[i][EBusinessProducts] = id_val;
cache_get_row(index, 19, data);
id_val = strval(data);
Business[i][EBusinessMaxProducts] = id_val;
Business[i][EBusinessPickup] = CreateDynamicPickup(Business[i][EBusinessOwner]>0?1239:1239, 16, Business[i][EBusinessEntranceX], Business[i][EBusinessEntranceY], Business[i][EBusinessEntranceZ]);
getBiz3DLabelText(i, data, sizeof(data));
Business[i][EBusinessText] = CreateDynamic3DTextLabel(data, 0xFFFFFFFF, Business[i][EBusinessEntranceX], Business[i][EBusinessEntranceY], Business[i][EBusinessEntranceZ]+1.5,10.0);
if(!IsDealership(i) && !IsFishStore(i) && !IsCarRental(i))
Business[i][EBusinessExitPickup] = CreateDynamicPickup(1318, 16, Business[i][EBusinessExitX],Business[i][EBusinessExitY],Business[i][EBusinessExitZ], Business[i][EBusinessVW], Business[i][EBusinessInterior]);
printf("Loaded business ID %d\n",Business[i][EBusinessID]);
}
if(bizinit == 0) {
sellInactiveBusinesses();
bizinit = 1;
}
printf("Businesses loaded.\n");
}
|
I don't get any error, but it just spawns business ID 0, but says there are 115 businesses. In the Database are also 115 businesses.
It only loads ID 0. |
|
After you make a business, try restarting the server and see if it appears.
|
|
Try to run that query in your PHPMyAdmin, does it show all the rows? Or only the first?
|
public onLoadBusiness() {
new rows,fields;
cache_get_data(rows,fields);
printf("Number of businesses: %d\n", rows);
for(new index=0;index<rows;index++) {
new i = findFreeBusiness();
Business[i][EBusinessID] = cache_get_row_int(index, 0); // business SQL id
cache_get_row(index, 1, Business[i][EBusinessName], 1, 64); // business name
Business[i][EBusinessOwner] = cache_get_row_int(index, 2); // owner SQL id
if(Business[i][EBusinessOwner] == 0)
format(Business[i][EBusinessOwnerName],MAX_PLAYER_NAME,"No-One");
else if(Business[i][EBusinessOwner] == -1)
format(Business[i][EBusinessOwnerName],MAX_PLAYER_NAME,"The State");
else
cache_get_row(index, 3, Business[i][EBusinessOwnerName], 1, MAX_PLAYER_NAME); //owner username
}
}