Loading problem (mysql)
#1

I got a problem with loading my vehicles properly, the problem I'm having is that at the CarInfo[idx][FactionVeh], it's supposed to output either 0 or 1 depending on what it reads in the table of course. However it always outputs 111?

pawn Code:
new vehfstats[14][40];
    new sql[100], row[512];
    format(sql, sizeof(sql), "SELECT COUNT(*) FROM vehicles");
    mysql_query(sql);
    mysql_store_result();
    mysql_fetch_row(row);
    totalfveh = strval(row);
    new idx = 0;
    while(idx < totalfveh)
    {
        format(sql, sizeof(sql), "SELECT * FROM vehicles WHERE VehID = %d", idx);
        mysql_query(sql);
        mysql_store_result();
        if(mysql_num_rows() > 0)
        {
            mysql_fetch_row(row);
            split(row, vehfstats, '|');
            CarInfo[idx][VehID] = strval(vehfstats[0]);
            CarInfo[idx][FactionID] = strval(vehfstats[1]);
            CarInfo[idx][Model] = strval(vehfstats[2]);
            CarInfo[idx][SpawnX] = floatstr(vehfstats[3]);
            CarInfo[idx][SpawnY] = floatstr(vehfstats[4]);
            CarInfo[idx][SpawnZ] = floatstr(vehfstats[5]);
            CarInfo[idx][SpawnAngle] = strval(vehfstats[6]);
            CarInfo[idx][Color1] = strval(vehfstats[7]);
            CarInfo[idx][Color2] = strval(vehfstats[8]);
            CarInfo[idx][FactionVeh] = strval(vehfstats[9]);
            CarInfo[idx][Owned] = strval(vehfstats[10]);
            strmid(CarInfo[idx][Owner], vehfstats[11], 0, strlen(vehfstats[11]), 255);
            strmid(CarInfo[idx][Plate], vehfstats[13], 0, strlen(vehfstats[13]), 255);
            AddStaticVehicleEx(strval(vehfstats[2]),strval(vehfstats[3]),strval(vehfstats[4]),strval(vehfstats[5]),strval(vehfstats[6]),strval(vehfstats[7]),strval(vehfstats[8]),6000);
            idx ++;
        }
    }
    mysql_free_result();
    printf("%d Vehicles loaded from database", totalfveh);
    return 1;
Output:
Code:
[02:12:46] [B] VehicleID:0 FactionID:2 ModelID:422 Owned:0 FactionVeh:111 Plate:
[02:12:46] [B] VehicleID:1 FactionID:2 ModelID:402 Owned:0 FactionVeh:111 Plate:
[02:12:46] [B] VehicleID:2 FactionID:2 ModelID:522 Owned:0 FactionVeh:111 Plate:
[02:12:46] [B] VehicleID:3 FactionID:0 ModelID:422 Owned:0 FactionVeh:111 Plate:RENT
[02:12:46] [B] VehicleID:4 FactionID:0 ModelID:422 Owned:0 FactionVeh:111 Plate:RENT
[02:12:46] [B] VehicleID:5 FactionID:0 ModelID:422 Owned:0 FactionVeh:111 Plate:RENT
[02:12:46] [B] VehicleID:6 FactionID:0 ModelID:422 Owned:0 FactionVeh:111 Plate:RENT
In the mysql log it shows the normal output or what it where supposed to output.

I can't seem to find a way to solve this, been trying a few things with no luck.

Thanks!
Reply
#2

Code:
new vehfstats[14][40];
    new sql[100], row[512];
    mysql_fetch_row(row);
    new totalfveh;
    new idx = 0;
    format(sql, sizeof(sql), "SELECT * FROM vehicles WHERE VehID = %d", idx);
    mysql_query(sql);
    mysql_store_result();
    totalfveh = mysql_num_rows(); // Don't waste another query.
    while(idx < totalfveh)
    {
        if(mysql_num_rows() > 0)
        {
            mysql_fetch_row(row);
            split(row, vehfstats, '|');
            CarInfo[idx][VehID] = strval(vehfstats[0]);
            CarInfo[idx][FactionID] = strval(vehfstats[1]);
            CarInfo[idx][Model] = strval(vehfstats[2]);
            CarInfo[idx][SpawnX] = floatstr(vehfstats[3]);
            CarInfo[idx][SpawnY] = floatstr(vehfstats[4]);
            CarInfo[idx][SpawnZ] = floatstr(vehfstats[5]);
            CarInfo[idx][SpawnAngle] = strval(vehfstats[6]);
            CarInfo[idx][Color1] = strval(vehfstats[7]);
            CarInfo[idx][Color2] = strval(vehfstats[8]);
            CarInfo[idx][FactionVeh] = strval(vehfstats[9]);
            CarInfo[idx][Owned] = strval(vehfstats[10]);
            strmid(CarInfo[idx][Owner], vehfstats[11], 0, strlen(vehfstats[11]), 255);
            strmid(CarInfo[idx][Plate], vehfstats[13], 0, strlen(vehfstats[13]), 255);
            AddStaticVehicleEx(strval(vehfstats[2]),strval(vehfstats[3]),strval(vehfstats[4]),strval(vehfstats[5]),strval(vehfstats[6]),strval(vehfstats[7]),strval(vehfstats[8]),6000);
            idx ++;
        }
    }
    mysql_free_result();
    printf("%d Vehicles loaded from database", totalfveh);
    return 1;
You were re-executing the query each time, no need.
Reply
#3

That would make it only run once? It's loading multiple vehicles not only 1, anyways didn't fix the 111 problem at FactionVeh
Reply
#4

Quote:
Originally Posted by oliverrud
View Post
That would make it only run once? It's loading multiple vehicles not only 1, anyways didn't fix the 111 problem at FactionVeh
Oops, didn't read your code properly, it's a mess. Why are you unloading it like that in the first place, it's a mess?

Use the proper query functions, alongside the get_field functions of whatever plugin you're using.
Reply
#5

Well, the query is working so what's the problem? And what is it that is so messy? I can easily look through it without being confused, however that's not the problem is it? I'm having a problem with for some odd reason the CarInfo[idx][FactionVeh] is outputting 111 no matter what.

All other ones are working fine it's only that one.
Reply
#6

This is all you need. Why would you make so many quries where you need only one?

pawn Code:
new idx = 0;
   
    mysql_query("SELECT * FROM vehicles");
    mysql_store_result();
   
    while(mysql_fetch_row(row) && idx < sizeof(CarInfo))
    {
            split(row, vehfstats, '|');
            CarInfo[idx][VehID] = strval(vehfstats[0]);
            CarInfo[idx][FactionID] = strval(vehfstats[1]);
            CarInfo[idx][Model] = strval(vehfstats[2]);
            CarInfo[idx][SpawnX] = floatstr(vehfstats[3]);
            CarInfo[idx][SpawnY] = floatstr(vehfstats[4]);
            CarInfo[idx][SpawnZ] = floatstr(vehfstats[5]);
            CarInfo[idx][SpawnAngle] = strval(vehfstats[6]);
            CarInfo[idx][Color1] = strval(vehfstats[7]);
            CarInfo[idx][Color2] = strval(vehfstats[8]);
            CarInfo[idx][FactionVeh] = strval(vehfstats[9]);
            CarInfo[idx][Owned] = strval(vehfstats[10]);
            strmid(CarInfo[idx][Owner], vehfstats[11], 0, strlen(vehfstats[11]), 255);
            strmid(CarInfo[idx][Plate], vehfstats[13], 0, strlen(vehfstats[13]), 255);
            AddStaticVehicleEx(strval(vehfstats[2]),strval(vehfstats[3]),strval(vehfstats[4]),strval(vehfstats[5]),strval(vehfstats[6]),strval(vehfstats[7]),strval(vehfstats[8]),6000);
            idx ++;
        }
    }
   
    mysql_free_result();
    printf("%d Vehicles loaded from database", idx);
Reply
#7

yes......
Reply
#8

Ah now I get it, anyways the FactionVeh = 111 is still not fixed? Anybody got a solution? The new loading is:

pawn Code:
new idx = 0;
    new vehfstats[14][40];
    new sql[100], row[512];
    mysql_query("SELECT * FROM vehicles");
    mysql_store_result();
    while(mysql_fetch_row(row) && idx < sizeof(CarInfo))
    {
        split(row, vehfstats, '|');
        CarInfo[idx][VehID] = strval(vehfstats[0]);
        CarInfo[idx][FactionID] = strval(vehfstats[1]);
        CarInfo[idx][Model] = strval(vehfstats[2]);
        CarInfo[idx][SpawnX] = floatstr(vehfstats[3]);
        CarInfo[idx][SpawnY] = floatstr(vehfstats[4]);
        CarInfo[idx][SpawnZ] = floatstr(vehfstats[5]);
        CarInfo[idx][SpawnAngle] = strval(vehfstats[6]);
        CarInfo[idx][Color1] = strval(vehfstats[7]);
        CarInfo[idx][Color2] = strval(vehfstats[8]);
        CarInfo[idx][FactionVeh] = strval(vehfstats[9]);
        CarInfo[idx][Owned] = strval(vehfstats[10]);
        strmid(CarInfo[idx][Owner], vehfstats[11], 0, strlen(vehfstats[11]), 255);
        strmid(CarInfo[idx][Plate], vehfstats[13], 0, strlen(vehfstats[13]), 255);
        AddStaticVehicleEx(strval(vehfstats[2]),strval(vehfstats[3]),strval(vehfstats[4]),strval(vehfstats[5]),strval(vehfstats[6]),strval(vehfstats[7]),strval(vehfstats[8]),6000);
        idx ++;
    }
    mysql_free_result();
    printf("%d Vehicles loaded from database", idx);
    return 1;
Reply
#9

And what's wrong with 111?
Reply
#10

It's supposed to give either 0 or 1, depends on what it tells on the mysql table row, but it always outputs 111
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)