SA-MP Forums Archive
Problem loading MySQL datas - 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 loading MySQL datas (/showthread.php?tid=528698)



Problem loading MySQL datas - FosterK - 29.07.2014

Hello everyone,

I would like to load data via MySQL.
When the ID is in the order (0, 1, 2, etc) the script works fine, but when I delete the entries (0,2,6,7) script bug

Here is my script:
Код:
public LoadPockets()
{
    new fields[61][40], row[150], row2[150];
    new Pockets_Count;
    new query[128];
    format(query, sizeof(query), "SELECT COUNT(*) FROM server_pockets");
    mysql_query(query);
    mysql_store_result();
    mysql_fetch_row(row2);
    Pockets_Count = strval(row2);
    if(!mysql_num_rows()) { mysql_free_result(); return; }
    for(new i=1; i <= Pockets_Count; i++)
    {
	format(query, sizeof(query), "SELECT * FROM server_pockets WHERE id = %d", i);
	mysql_query(query);
	mysql_store_result();
	mysql_fetch_row(row);
	split(row, fields, '|');
        PocketInfos[i][ID] = strval(fields[0]);
        PocketInfos[i][OBJECTID] = strval(fields[1]);
        PocketInfos[i][CHARACTER] = strval(fields[2]);
        TotalPockets++;
	mysql_free_result();
    }
    mysql_free_result();
}
I'm stuck on this problem from two days.
Thank you in advance to whoever can help me


Re: Problem loading MySQL datas - BroZeus - 29.07.2014

not sure but try this --
pawn Код:
public LoadPockets()
{
    new fields[61][40], row[150], row2[150];
    new r;//added this
    new Pockets_Count;
    new query[128];
    format(query, sizeof(query), "SELECT COUNT(*) FROM server_pockets");
    mysql_query(query);
    mysql_store_result();
    mysql_fetch_row(row2);
    Pockets_Count = strval(row2);
    if(!mysql_num_rows()) { mysql_free_result(); return; }
    for(new i=1; i <= Pockets_Count; i++)
    {
    format(query, sizeof(query), "SELECT * FROM server_pockets WHERE id = %d", i);
    mysql_query(query);
    mysql_store_result();
        r = mysql_num_rows();//added this
        if(!r)continue; //added this
    mysql_fetch_row(row);
    split(row, fields, '|');
        PocketInfos[i][ID] = strval(fields[0]);
        PocketInfos[i][OBJECTID] = strval(fields[1]);
        PocketInfos[i][CHARACTER] = strval(fields[2]);
        TotalPockets++;
    mysql_free_result();
    }
    mysql_free_result();
}



Re : Problem loading MySQL datas - FosterK - 29.07.2014

Thank you so infact it works until it gets to the time that id has been removed, so what should be done is to "jump" the deleted id (2 => 4).
Resolved, thx !


Re: Problem loading MySQL datas - Blademaster680 - 29.07.2014

If you want to reorder the ID's in your database. you can delete the ID column and then recreate it again and it will automatically put everyone in order again. so if there are ID 1, 2, 3, 4. And I delete ID 2. It will end up 1, 3, 4. But if you delete and recreate the column ID. it will now be: 1, 2, 3.