[MySQL] Problem with while loop, for ...
#1

Good evening,
This is the 6 o'clock I'm on the problem, I can not find a solution. I am creating my GameMode, I made the login system, it works ... I am trying to show the vehicles contained in a MySQL table by making a loop that increments the id parameter, which is different to the vehicle (plate, engine off base ...).

Then the server connection is good (it works for the login and test ...), I only have the problem of the loop ... I try with a "For", "While", following the wiki, always the same. I begin to despair ...

This is my code:

Код:
	mysql_query("SELECT * FROM `vehicules`");
	mysql_store_result();
	mysql_retrieve_row();
	
	new ID[8], Model[16], Pos_x[512], Pos_y[512], Pos_z[512], Pos_a[512], Couleur_1[16], Couleur_2[16], Plaque[512];
	new Alarme[8], Proprietaire[1024], Essence[256], Prix[256], Status_de_vente[8];
	
	new vehID[8];
	mysql_fetch_field_row(vehID, "id");
	ID = vehID;
	
	if(mysql_num_rows())
    {
		while(mysql_retrieve_row())
		{
			VehicleInfo[strval(ID)][vID] = strval(ID);
			mysql_fetch_field_row(Model, "Model"); VehicleInfo[strval(ID)][vModel] = strval(Model);
			mysql_fetch_field_row(Pos_x, "Pos_x"); VehicleInfo[strval(ID)][vPos_x] = strval(Pos_x);
			mysql_fetch_field_row(Pos_y, "Pos_y"); VehicleInfo[strval(ID)][vPos_y] = strval(Pos_y);
			mysql_fetch_field_row(Pos_z, "Pos_z"); VehicleInfo[strval(ID)][vPos_z] = strval(Pos_z);
			mysql_fetch_field_row(Pos_a, "Pos_a"); VehicleInfo[strval(ID)][vPos_a] = strval(Pos_a);
			mysql_fetch_field_row(Couleur_1, "Couleur_1"); VehicleInfo[strval(ID)][vCouleur_1] = strval(Couleur_1);
			mysql_fetch_field_row(Couleur_2, "Couleur_2"); VehicleInfo[strval(ID)][vCouleur_2] = strval(Couleur_2);
			mysql_fetch_field_row(Plaque, "Plaque"); VehicleInfo[strval(ID)][vPlaque] = strval(Plaque);
			mysql_fetch_field_row(Alarme, "Alarme"); VehicleInfo[strval(ID)][vAlarme] = strval(Alarme);
			mysql_fetch_field_row(Proprietaire, "Proprietaire"); VehicleInfo[strval(ID)][vProprietaire] = strval(Proprietaire);
			mysql_fetch_field_row(Essence, "Essence"); VehicleInfo[strval(ID)][vEssence] = strval(Essence);
			mysql_fetch_field_row(Prix, "Prix"); VehicleInfo[strval(ID)][vPrix] = strval(Prix);
			mysql_fetch_field_row(Status_de_vente, "Status_de_vente"); VehicleInfo[strval(ID)][vStatus_de_vente] = strval(Status_de_vente);

			AddStaticVehicle(VehicleInfo[strval(ID)][vModel], VehicleInfo[strval(ID)][vPos_x], VehicleInfo[strval(ID)][vPos_y], VehicleInfo[strval(ID)][vPos_z], VehicleInfo[strval(ID)][vPos_a], VehicleInfo[strval(ID)][vCouleur_1], VehicleInfo[strval(ID)][vCouleur_2]);
			SetVehicleNumberPlate(strval(ID), VehicleInfo[strval(ID)][vPlaque]);

			GetVehicleParamsEx(strval(ID), engine_param, lights_param, alarm_param, doors_param, bonnet_param, boot_param, objective_param);
			SetVehicleParamsEx(strval(ID), false, lights_param, alarm_param, doors_param, bonnet_param, boot_param, objective_param);
			
			ID++;
		}
	}
	mysql_free_result();
I try different stuff, I can not, I really need help!
Thank you in advance of the writers.

PS: Sorry for my English, I am French, I use "******" ...
Reply
#2

What kind of plugin are you using?
Also, you should use sscanf2 for loading data from MySQL.
Reply
#3

No, sorry look this;

Problem solved! =D

- Explanations for those who try the same mistake
Код:
new ID [8], Model [16], Pos_x [512], Pos_y [512], Pos_z [512], Pos_a [512], Couleur_1 [16], Couleur_2 [16], Plate [512];
New Alarm [8], Owner [1024] Essence [256] Price [256], Status_de_vente [8];

New vehID [8];
mysql_fetch_field_row (vehID, "id");
ID = vehID;
While its no use!

That's just the code:

Код:
ConnectMySQL();
	format(query, sizeof(query), "SELECT * FROM vehicules");
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows())
    {
		if(mysql_retrieve_row())
		{
			new i = 0;
			while(i < mysql_num_rows())
			{
				format(query, sizeof(query), "SELECT * FROM vehicules WHERE id=%d", i);
				mysql_query(query);
				mysql_retrieve_row();
				
				mysql_fetch_field_row(result, "Model"); VehicleInfo[i][vModel] = strval(result);
				mysql_fetch_field_row(result, "Pos_x"); VehicleInfo[i][vPos_x] = strval(result);
				mysql_fetch_field_row(result, "Pos_y"); VehicleInfo[i][vPos_y] = strval(result);
				mysql_fetch_field_row(result, "Pos_z"); VehicleInfo[i][vPos_z] = strval(result);
				mysql_fetch_field_row(result, "Pos_a"); VehicleInfo[i][vPos_a] = strval(result);
				mysql_fetch_field_row(result, "Couleur_1"); VehicleInfo[i][vCouleur_1] = strval(result);
				mysql_fetch_field_row(result, "Couleur_2"); VehicleInfo[i][vCouleur_2] = strval(result);
				mysql_fetch_field_row(result, "Plaque"); VehicleInfo[i][vPlaque] = strval(result);
				mysql_fetch_field_row(result, "Alarme"); VehicleInfo[i][vAlarme] = strval(result);
				mysql_fetch_field_row(result, "Proprietaire"); VehicleInfo[i][vProprietaire] = strval(result);
				mysql_fetch_field_row(result, "Essence"); VehicleInfo[i][vEssence] = strval(result);
				mysql_fetch_field_row(result, "Prix"); VehicleInfo[i][vPrix] = strval(result);
				mysql_fetch_field_row(result, "Status_de_vente"); VehicleInfo[i][vStatus_de_vente] = strval(result);
				
				AddStaticVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPos_x], VehicleInfo[i][vPos_y], VehicleInfo[i][vPos_z], VehicleInfo[i][vPos_a], VehicleInfo[i][vCouleur_1], VehicleInfo[i][vCouleur_2]);
				SetVehicleNumberPlate(i, VehicleInfo[i][vPlaque]);

				GetVehicleParamsEx(i, engine_param, lights_param, alarm_param, doors_param, bonnet_param, boot_param, objective_param);
				SetVehicleParamsEx(i, false, lights_param, alarm_param, doors_param, bonnet_param, boot_param, objective_param);
				i++;
			}
		}
	}
	mysql_free_result();
Thank you
Reply
#4

Good to see you solved it.
I have a question, 'cause I never seen such function before:
Код:
mysql_retrieve_row
Which plugin are you using?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)