problem with mysql and loop - 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: problem with mysql and loop (
/showthread.php?tid=461707)
problem with mysql and loop -
Bob_Dylan - 03.09.2013
Hello! I'm doing a house system and I need use loop for it. The loop is for create a ID for the house. I don't wanna auto increment, I wanna the IDs in order always (1,2,3,4) and not (1,3, 4, 7) because of deletion of a house.
But, for get the numbers of row, I have to create a new public e call it with mysql_format_query and that way I don't stop (break) the loop.
How can do it?
Code:
pawn Код:
new rows, field, IDH, str[120];
for(new h = 1; h < 300; h++)
{
mysql_format(DB, str, "SELECT * FROM `house_info` WHERE `ID` = %d", h);
mysql_function_query(DB, str, true, "", "");
cache_get_data(rows, field, DB);
if(!rows)
{
IDH = h;
break;
}
}
The way up don't work because no callback is called
Sorry for my bad english, I don't know english very well and I don't use ****** translator.
I hope you understand. Help-me, please! Thanks!
Re: problem with mysql and loop -
Borg - 03.09.2013
you can remove filter in your query. i.e. you can select all houses in one query and then load it one by one.
for example:
pawn Код:
new rows, field, IDH, str[120];
mysql_query("SELECT * FROM `house_info`");
...
new idx = 1;
while(mysql_retrieve_row())
{
//now idx - your house id
cache_get_data(rows, field, DB);
if(!rows)
{
IDH = h;
break;
}
idx++;
}
...
Re: problem with mysql and loop -
Bob_Dylan - 04.09.2013
Quote:
Originally Posted by Borg
you can remove filter in your query. i.e. you can select all houses in one query and then load it one by one.
for example:
pawn Код:
new rows, field, IDH, str[120]; mysql_query("SELECT * FROM `house_info`"); ... new idx = 1; while(mysql_retrieve_row()) { //now idx - your house id cache_get_data(rows, field, DB); if(!rows) { IDH = h; break; } idx++; } ...
|
this is not working, save all data to zero.