PDA

View Full Version : Mysql Vehicle Loading Issue


Rokzlive
23/12/2011, 04:35 AM
I have the following function to load vehicles from my mysql database.

stock LoadServerVehicles()
{
new count = 0;
for(new i=1; i<MAX_VEHICLES; i++)
{
format(query, sizeof(query), "SELECT * FROM servervehicles WHERE `id` = %d",i);
mysql_query(query);
printf(query);
mysql_store_result();
if(mysql_num_rows() == 0)
{
mysql_free_result();
continue;//breaks out of the loops so if it's at loop 10 and there is nothing in the db, it will skip that loop so nothing under it gets executed
}
mysql_fetch_row_format(row, "|");
explode(row, field, "|");
servervehicledata[i][ID] = strval(field[0]);
servervehicledata[i][mdl] = strval(field[1]);
servervehicledata[i][xpos] = floatstr(field[2]);
servervehicledata[i][ypos] = floatstr(field[3]);
servervehicledata[i][zpos] = floatstr(field[4]);
servervehicledata[i][angle] = floatstr(field[5]);
servervehicledata[i][color1] = strval(field[6]);
servervehicledata[i][color2] = strval(field[7]);
servervehicledata[i][respawndelay] = strval(field[8]);
i = AddStaticVehicleEx(servervehicledata[i][mdl],servervehicledata[i][xpos],servervehicledata[i][ypos],servervehicledata[i][zpos],servervehicledata[i][angle],servervehicledata[i][color1],servervehicledata[i][color2],servervehicledata[i][respawndelay]);
mysql_free_result();
}
return printf("%d vehicles loaded.",count);
}

explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) // Created by Westie
{
new
iNode,
iPointer,
iPrevious = -1,
iDelimiter = strlen(sDelimiter);

while(iNode < iVertices)
{
iPointer = strfind(sSource, sDelimiter, false, iPointer);

if(iPointer == -1)
{
strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
break;
}
else
{
strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
}

iPrevious = (iPointer += iDelimiter);
++iNode;
}
return iPrevious;
}

Its not loading a single vehicle, but i have 273 vehicles in my database.

Rokzlive
23/12/2011, 09:53 AM
Uhhh, anyone? Please? :/