SA-MP Forums Archive
MySQL loading data with loops? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL loading data with loops? (/showthread.php?tid=648622)



MySQL loading data with loops? - CMH - 25.01.2018

Is there any way to load the columns in Mysql database with a loop?

I have the following columns in the database:
Код:
Object1, Object2, Object3, Object4, Object5
I tried something like that, but I think it's got to be formatted, I do not know how.
Код:
	if(cache_num_rows() > 0)
	{
		for(new i=0; t < 5; i++)	
		{  
			cache_get_value_int(0, 		"Object%d", 		Player[playerid][Object][%d]);	

		}
	}



Re: MySQL loading data with loops? - DobbysGamertag - 25.01.2018

Yes.

Swap that
pawn Код:
t < 5; i++
for
pawn Код:
t < cache_num_rows(); i++)
. Then the row number (first parameter) becomes i, instead of 0, 1, 2, 3 etc.

This is how i used to load a few hundred vehicles anyway, possibly someone has a better way of doing it.

pawn Код:
if(cache_num_rows() > 0)
    {
        for(new i=0; t < cache_num_rows(); i++)
        {  
            cache_get_value_int(i,      "Object%d",         Player[playerid][Object][%d])

        }
    }



Re: MySQL loading data with loops? - CMH - 25.01.2018

She does not want to work, I did that
Код:
	if(cache_num_rows() > 0)
	{
		for(new i=1; i <cache_num_rows (); i++)	
		{  
			cache_get_value_int(i, 		"S%d", 				pInventory[playerid][invSlot][i]);	
		}

	}



Re: MySQL loading data with loops? - CMH - 25.01.2018

I want to load a loop all the objects: Object1 Object2, etc.
But I do not find a modali ...
That's what the database looks like




Re: MySQL loading data with loops? - Fratello - 25.01.2018

Code seems to be fine. I have a similar code in my testing mode too.

So what exactly is the problem? Data isn't fetched properly? If so, look for any warnings/errors in 'mysql/warnings' in your server directory.

If objects are not being created? How could they even create? You didn't use Create(Dynamic)Object function.