MySQL Help
#1

Hello, I am doing a MySQL Vehicle System. I have a trouble loading the cars, this code only load the first row from my table, currently I have three vehicles instead.

Код:
for (new i = 1; i < num_rows; i++)
    {
		new cosa[300];
		format(cosa, sizeof(cosa), "ID: %d | Rows: %d", i, num_rows);
		printf(cosa);
		cache_get_field_content(i, "CarID", data), VehicleSystem[i][CarID] = strval(data);
		cache_get_field_content(i, "Model", data), VehicleSystem[i][Model]=strval(data);
		cache_get_field_content(i, "Locked", data), VehicleSystem[i][Locked]=strval(data);
		cache_get_field_content(i, "CarX", data), VehicleSystem[i][Carx]=strval(data);
		cache_get_field_content(i, "CarY", data), VehicleSystem[i][Cary]=strval(data);
		cache_get_field_content(i, "CarZ", data), VehicleSystem[i][Carz]=strval(data);
		cache_get_field_content(i, "CarA", data), VehicleSystem[i][Cara]=strval(data);
		cache_get_field_content(i, "Color1", data), VehicleSystem[i][Color1]=strval(data);
		cache_get_field_content(i, "Color2", data), VehicleSystem[i][Color2]=strval(data);
		cache_get_field_content(i, "Price", data), VehicleSystem[i][Price]=strval(data);
		cache_get_field_content(i, "Sell", data), VehicleSystem[i][Sell]=strval(data);
		cache_get_field_content(i, "Owner", data2), strmid(VehicleSystem[i][Owner],data2,0,30,30);
		new carr = CreateVehicle(VehicleSystem[i][Model],VehicleSystem[i][Carx],VehicleSystem[i][Cary],VehicleSystem[i][Carz]+5,VehicleSystem[i][Cara],VehicleSystem[i][Color1],VehicleSystem[i][Color2],600000);
  	}
In my server.cfg it shows printed:

Код:
ID: 1 | Rows: 3
And should be:

Код:
ID: 1 | Rows: 3
ID: 2 | Rows: 3
ID: 3 | Rows: 3
Thanks a lot!
Reply
#2

This loop atleast will never call 3, for your statement is "i < 3" (since num rows is 3). This means it will keep looping as long i is below 3.
Also you don't need to format a string for a print function.
You have: print(msg[]) and printf, and with printf you can add these vars (printf("i=d",i)

Anyway I can't see what's wrong futher so quick.
Would love to help but I am currently on my phone

P.s.
PHP код:
new num_rows1;
while (
c+1)
{
//cache content etc
i++;//after creating the vehicle!

Reply
#3

Thanks, I'll check with while. But with my Code should return 2 ids and only returns one...
Reply
#4

Rows start from 0 so having 3 rows is 0 to 2.
Reply
#5

Even for MySQL? I haven't scripted in a few years (began a few weeks ago again) and I thought that mysql_num_rows returns the ammount of rows.. If you have 1 row I'd hardly think num_rows then would return 0 as there is 1 row and not 0
Reply
#6

If there is 1 row, you'll need to retrieve the data from rowid 0 otherwise you will get an error for invalid row index ('1').
Reply
#7

If I put 0 it shows the 1st row (ID 0) thats why I start retrieving info from cell 2 (1 in for statement). But always shows only one rйcord.
Reply
#8

i have already import sql, next ?
Reply
#9

If you start from rowid 1, you will always miss the first record selected. The correct way is:
pawn Код:
for (new i = 0; i < num_rows; i++)
and I also noticed that you're using cache_get_field_content + strval. What version of the mysql plugin are you using? After R7 (latest being R39-6), these two native functions: cache_get_field_content_int and cache_get_field_content_float were added.
Reply
#10

I'm using R39-7, but what's the diference? The cache_get_field_content works in my other systems like House System, I don't have any trouble with it.

Can you tell me if there's anlther way easy to retrieve the data? Lot of thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)