MySQL Load car not working
#1

Hello, now i making car system, but now, when i wanna to load a car, which are in DB(DataBase), not loading, i am loading on 'OnGamemodeInit' callback, i try'ed to make loading on command, jus nothing happens, there go, code -

Код HTML:
stock LoadPriVeh()
{
	new Query[1024], ID, Modeliukas, Owners, Spalvos1, Spalvos2, Pos[4], Nusipirkau;
	
	
	format(Query, sizeof(Query), "SELECT * FROM `automobiliai` WHERE 'ID'");
	mysql_store_result();

	
 	if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Query))
        {
		MasinosI[ID][Modelis] = Modeliukas;
		MasinosI[ID][Savininkass] = Owners;
		MasinosI[ID][Spalva1] = Spalvos1;
		MasinosI[ID][Spalva2] = Spalvos2;
		MasinosI[ID][x] = Pos[0];
		MasinosI[ID][y] = Pos[1];
		MasinosI[ID][z] = Pos[2];
		MasinosI[ID][a] = Pos[3];
		MasinosI[ID][Perkama] = Nusipirkau;
	
	
		new Masinukas = CreateVehicle(Modeliukas, Pos[0], Pos[1], Pos[2], Pos[3], Spalvos1, Spalvos2, 500000);
		SetVehicleNumberPlate(Masinukas, "Cbb");
		}
	}
	return 1;
}
Reply
#2

Код:
WHERE 'ID'
What's the point of this WHERE clause?

Also show us your mysql log. And one more note:
pawn Код:
if(mysql_num_rows() > 0)
This code is pointless. If there are no rows the while loop will simply not run.
Reply
#3

Your problem is simply because you're not actually returning a vehicle id from the MySQL server. You've defined ID but not assigned any data.

So, everytime you're using ID the script is doing this:

pawn Код:
MasinosI[0][x] = Pos[0];
MasinosI[0][y] = Pos[1];
MasinosI[0][z] = Pos[2];
MasinosI[0][a] = Pos[3];
Instead of whatever ID the vehicle is. Select everything from the Cars database and make sure to assign ID a value in a loop. I'm using MySQL R33 for this example, you should really upgrade as it's way faster. You'll get the jist of it anyways:

pawn Код:
if(cache_num_rows() != 0) // Example of loading vehicles using MySQL R33. Forgot how R6 and under works.
    {
        for(new i = 0; i != cache_num_rows(); i++)
        {
            cache_get_field_content_int(i, "Value", MasinosI[i][Value]); // Fetching & Assigning Data
            cache_get_field_content_int(i, "Value", MasinosI[i][Value]); // Fetching & Assigning Data
            cache_get_field_content_int(i, "Value", MasinosI[i][Value]); // Fetching & Assigning Data
            cache_get_field_content_int(i, "Value", MasinosI[i][Value]); // Fetching & Assigning Data

            // Then go on to create the vehicle
        }
    }
Reply
#4

Wow, how did no one notice yet that there's no query being actually sent?
Reply
#5

Your query is incorrect lolol
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Wow, how did no one notice yet that there's no query being actually sent?
I was under the assumption that the query was sent XD

Still, even if a query was sent it still wouldn't work as I previously pointed out
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)