SA-MP Forums Archive
Best way to save houses to MySQL - 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: Best way to save houses to MySQL (/showthread.php?tid=509207)



Best way to save houses to MySQL - AphexCCFC - 25.04.2014

This doesn't work but what would be the best way to save all house information?

pawn Код:
stock SaveHouses()
{
    new query[500], rows, fields;
    cache_get_data(rows, fields, g_Handle);

    new id = 0;
    if(rows)
    {
        while(id <= rows-1)
        {
            format(query, sizeof(query), "UPDATE `Houses` SET `HouseID` = %d, `Address` = '%s', `Price` = %d, `EnterX` = %f, `EnterY` = %f, `EnterZ` = %f, `EnterA` = %f, `ExitX` = %f, `ExitY` = %f, `ExitZ` = %f, `ExitA` = %f, `Interior` = %d, `Type` = %d WHERE `HouseID` = %d",
            HouseInfo[id][hHouseID],
            HouseInfo[id][hAddress],
            HouseInfo[id][hPrice],
            HouseInfo[id][hEnterPos][0],
            HouseInfo[id][hEnterPos][1],
            HouseInfo[id][hEnterPos][2],
            HouseInfo[id][hEnterPos][3],
            HouseInfo[id][hExitPos][0],
            HouseInfo[id][hExitPos][1],
            HouseInfo[id][hExitPos][2],
            HouseInfo[id][hExitPos][3],
            HouseInfo[id][hInterior],
            HouseInfo[id][hType]
            );
           
            mysql_function_query(g_Handle, query, false, "", "");
            id ++;
        }
    }
    return 1;
}



Re : Best way to save houses to MySQL - S4t3K - 25.04.2014

First, you can use a for(each) loop instead of a while.

Secondly, a 500 chars query isn't very useful. 256 will most likely suffy in your case.

I think that's all I can tell for now, but I'm pretty tired, I may have missed something to optimize.