SA-MP Forums Archive
mysql_fetch_int - 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: mysql_fetch_int (/showthread.php?tid=464584)



mysql_fetch_int - saamp - 17.09.2013

I have a table named pAccounts, and my first row is playerID. The second row is playerName. I do like this:
pawn Код:
stock RetrieveID(const name[])
{
    new str[128];
    format(str, 128, "SELECT `playerID` FROM `pAccounts` WHERE `playerName` = '%s'", name);
    mysql_query(str);
    mysql_store_result(); // Store the result

    new resultID = -1;
    if(mysql_num_rows())
    {
        resultID = mysql_fetch_int();
    }
    mysql_free_result(); // Free the result
    return resultID;
}

// Somewhere ( of course, the database connection is established )
printf("%d", RetrieveID("MyName"));
The result is: -1 ( in my table, playerID is 5 ).

I can confirm to you that MyName it's already on my table, and the condition if(mysql_num_rows()) is evaluated as true.