Why is this not loading MySQL data into the variables properly?
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Adress is string so don't use strval for it:
pawn Код:
cache_get_row(0, 1, HouseInfo[id][hAddress], g_Handle, /* SIZE OF hAdress HERE */);
Also a suggestion: it would be better if you used a while loop so you can check if the rows are not more than the size of HouseInfo. Just to prevent a run time error 4 in case that was about to happen.
Thanks, it works except it only loads the first house in the database row. I've used a debug and it shows that two houses are called from the database, but it only shows the pickup and text label for the first one.

pawn Код:
public HousesLoad()
{
    new temp[400], string[400], rows, fields;
    cache_get_data(rows, fields, g_Handle);

    if(rows)
    {
        for(new id = 0; id < MAX_HOUSES; id++)
        {
            cache_get_row(0, 0, temp, g_Handle), HouseInfo[id][hHouseID] = strval(temp);
            cache_get_row(0, 1, HouseInfo[id][hAddress], g_Handle, 31);
            cache_get_row(0, 2, temp, g_Handle), HouseInfo[id][hPrice] = strval(temp);
            cache_get_row(0, 3, temp, g_Handle), HouseInfo[id][hEnterPos][0] = floatstr(temp);
            cache_get_row(0, 4, temp, g_Handle), HouseInfo[id][hEnterPos][1] = floatstr(temp);
            cache_get_row(0, 5, temp, g_Handle), HouseInfo[id][hEnterPos][2] = floatstr(temp);
            cache_get_row(0, 6, temp, g_Handle), HouseInfo[id][hExitPos][0] = floatstr(temp);
            cache_get_row(0, 7, temp, g_Handle), HouseInfo[id][hExitPos][1] = floatstr(temp);
            cache_get_row(0, 8, temp, g_Handle), HouseInfo[id][hExitPos][2] = floatstr(temp);

            HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
            format(string,sizeof(string),"HouseID: %d\nAddress: %s\nPrice: %d", HouseInfo[id][hHouseID], HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
            HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, -1, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100);
            break;
        }
        printf("%i houses loaded.", rows); // This shows that two houses have been loaded.
    }
    return 1;
}
Also, I'm using the up to date MySQL plugin so not sure what while loop I could use?
Thanks. Giving me headache been stuck on this for over a week but managed to code more complicated things and get them working
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)