Iterators problem with mysql -
Oficer - 01.02.2019
PHP код:
stock save(playerid)
{
new Iterator: test_iter<20>;
new tmp_uid, nick[30];
mysql_query(MyDB, "SELECT uid, Nick FROM players WHERE PD = 1");
new j = cache_num_rows();
for(new nr = 0; nr < j; nr++)
{
cache_get_value_int(nr, "uid", tmp_uid);
cache_get_value(nr, "Nick", nick, 30);
printf("From sql: %d",tmp_uid);
Iter_Add(test_iter, tmp_uid);
}
foreach(new load : test_iter)
{
printf("From iter: %d", load);
}
}
Result:
From sql: 1,2,3,4
From iter: 1
Why iter save only first number?
Re: Iterators problem with mysql -
SymonClash - 01.02.2019
Just use IterCount instead of foreach.
Re: Iterators problem with mysql -
Oficer - 01.02.2019
But, I want add uid from sql into iterator. ((When I use IterCount result is 1, why only 1 element is save?))
Re: Iterators problem with mysql -
Oficer - 01.02.2019
@ref
Re: Iterators problem with mysql -
m4karow - 01.02.2019
what do you want to accomplish?
Re: Iterators problem with mysql -
Oficer - 01.02.2019
I want add all numbers of uid from query into test_iter
Re: Iterators problem with mysql -
m4karow - 01.02.2019
Quote:
Originally Posted by Oficer
I want add all numbers of uid from query into test_iter
|
You only can add values to the interator to it's size ( new Iterator:Example<
32>; )
For example:
Код:
hook OnScriptInit()
{
new Iterator:Example<32>;
for(new idx; idx < 32; idx++)
{
new index = random(128);
Iter_Add(Example, index);
}
foreach(new id : Example)
printf("%i", id);
}
Only theese numbers added for me
Sorry for my english
Re: Iterators problem with mysql -
Oficer - 02.02.2019
This example is ok, but when I want add values from database, iterator save only first record. Just like here:
PHP код:
stock test2(playerid)
{
new Iterator : Iter_Test<20>;
mysql_query(MyDB, "SELECT Money from players");
new money, info[128];
for(new i = 0, j = cache_num_rows(); i != j; ++i)
{
cache_get_value_int(i,"Money", money);
Iter_Add(Iter_Test, money);
format(info, sizeof(info), "Money: %d", money);
SCM(playerid, 0xFFFFFFFF, money);
}
foreach(new id : Iter_Test)
{
printf("%d", id);
}
return 1;
}
Same, iterator don't save all records, but only one:
SCM >> 150, 2000, 350
print Iter_test in foreach, return only 150
Re: Iterators problem with mysql -
Calisthenics - 02.02.2019
m4karow already mentioned it. The size of the iterator matters. If the size in the example is 20, only numbers between 0 and 19 can be added to the iterator and any other will be ignored.
Why do you want to use an iterator and not a simple array? What is the purpose of saving money in an iterator?
Re: Iterators problem with mysql -
Oficer - 02.02.2019
This is only example, I try save data from database into iterator (uid in list of players). In DB I have 3 uid (3,4,5), but iterator saving only first record (3), so size is right. I don't know why saved only 1 uid.