problem with mysql and loop
#1

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!
Reply
#2

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++;
}
...
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)