SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 06/10/2011, 04:50 AM   #1
Urefeu
Big Clucker
 
Join Date: Jul 2011
Posts: 137
Reputation: 0
Default DB Loop

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 :

Code:
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
__________________
Urefeu is offline   Reply With Quote
Old 06/10/2011, 04:55 AM   #2
thiaZ_
Big Clucker
 
Join Date: Nov 2009
Posts: 127
Reputation: 7
Default Re: DB Loop

Possibly, you have to call mysql_free_result() after the loop.
thiaZ_ is offline   Reply With Quote
Old 06/10/2011, 05:09 AM   #3
Urefeu
Big Clucker
 
Join Date: Jul 2011
Posts: 137
Reputation: 0
Default Re : DB Loop

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

Thank you!
__________________
Urefeu is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a loop. Jack_Leslie Scripting Help 8 22/09/2011 10:37 AM
[Help] On loop CheeseSoul Help Archive 1 23/01/2011 04:55 PM
[Map] Big loop kurta999 Maps 3 24/10/2010 07:41 PM


All times are GMT. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.