DB Loop
#1

Hello.

J'ai un code pour faire spawn mes vйhicules.

Avant, je comptais le nombre d'entrйes dans ma table et je faisais un SELECT par entrйe, ce qui faisait un peu long (surtout que je faisais la mкme chose pour les maisons, les personnages, les biz...)

J'ai essayй d'optimiser le code ainsi :

Код:
mysql_query("SELECT * FROM `vehicles`");
    mysql_store_result();
    new vrows = mysql_num_rows();
	new vi = 1;
    mysql_free_result();
	if(vrows)
    {
        while(mysql_retrieve_row()) {
	        mysql_fetch_field_row(res, "model"); v[vi][model] = strval(res);
	        mysql_fetch_field_row(res, "price"); v[vi][price] = strval(res);
	        mysql_fetch_field_row(res, "state"); v[vi][state] = strval(res);
	        mysql_fetch_field_row(v[vi][owner], "owner");
	        mysql_fetch_field_row(res, "s_x"); v[vi][spawn_x] = strval(res);
	        mysql_fetch_field_row(res, "s_y"); v[vi][spawn_y] = strval(res);
	        mysql_fetch_field_row(res, "s_z"); v[vi][spawn_z] = strval(res);
	        mysql_fetch_field_row(res, "s_angle"); v[vi][spawn_angle] = strval(res);
	        mysql_fetch_field_row(res, "color1"); v[vi][color1] = strval(res);
	        mysql_fetch_field_row(res, "color2"); v[vi][color2] = strval(res);

	        v[vi][id] = CreateVehicle(v[vi][model], v[vi][spawn_x], v[vi][spawn_y], v[vi][spawn_z], v[vi][spawn_angle], v[vi][color1], v[vi][color2], -1);
			vi++;
		}
    }
res is an array, and I have also v[MAX_VEHICLES] [vData], vData is an enum of all the information on the vehicle ...

But it does not work, nothing is spawn ...

How do I get this code? I have no errors!

thank you
Reply
#2

Possibly, you have to call mysql_free_result() after the loop.
Reply
#3

Yes, I had to place the following mysql_free_result inftead before, I had zapped ^ ^

Thank you!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)