Gothic Online Forums
MySql modul - Printable Version

+- Gothic Online Forums (https://archive.gothic-online.com)
+-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html)
+--- Forum: Scripting Help (https://archive.gothic-online.com/forum-12.html)
+--- Thread: MySql modul (/thread-1861.html)



MySql modul - Baster - 28.10.2016

Hi.
How to get the data from the second or third row?

local query = mysql_query(handler, "select * from...");
local rowCount = mysql_num_row(query) // rowCount = 4

//Further

local data = mysql_fetch_row(query);

or

local data = mysql_fetch_assoc(query);



I have access to the data of the first row.


RE: MySql modul - Galin - 28.10.2016

Code:
function queryGetAll(query)
{
    local result = [];
    local mysql_result = mysql_query(database, query);
        
    local count = mysql_num_rows(mysql_result);
    for(local i=0; i<count; i++)
    {
        result.push(mysql_fetch_assoc(mysql_result));
    }
        
    mysql_free_result(mysql_result);
        
    return result;
}



RE: MySql modul - Nubzior - 28.10.2016

Squirrel Script
  1. local result = mysql_query(mysqlHandler, "SELECT * FROM `player_items` WHERE `player_id` = " + getGUIDbyLogin(getPlayerName(pid)) + ";");
  2. if(result)
  3. {
  4. local row;
  5. while ((row = mysql_fetch_assoc(result)))
  6. {
  7. callClientFunc(pid, "giveItem", row["instance"], row["amount"]);
  8. }
  9.  
  10. mysql_free_result(result);
  11. }





RE: MySql modul - Baster - 31.10.2016

Thank you, guys.