Loading problem (mysql)
#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


Messages In This Thread
Loading problem (mysql) - by oliverrud - 07.07.2010, 00:17
Re: Loading problem (mysql) - by Calgon - 07.07.2010, 00:23
Re: Loading problem (mysql) - by oliverrud - 07.07.2010, 00:26
Re: Loading problem (mysql) - by Calgon - 07.07.2010, 00:32
Re: Loading problem (mysql) - by oliverrud - 07.07.2010, 00:37
Re: Loading problem (mysql) - by Sergei - 07.07.2010, 00:55
Re: Loading problem (mysql) - by TheKingOfSamp - 07.07.2010, 02:58
Re: Loading problem (mysql) - by oliverrud - 07.07.2010, 06:04
Re: Loading problem (mysql) - by Sergei - 07.07.2010, 07:49
Re: Loading problem (mysql) - by oliverrud - 07.07.2010, 10:39

Forum Jump:


Users browsing this thread: 3 Guest(s)