how to get max field in 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: how to get max field in mysql (
/showthread.php?tid=308933)
how to get max field in mysql -
System64 - 05.01.2012
Hi guys, I have a small problem, I want to get max house id from my house table, I don't know, I tried this
pawn Код:
mysql_format(1, Query, "SELECT MAX(`House ID`) FROM `pf_houses`");
mysql_query(Query);
printf("Query: %s", Query);
mysql_store_result();
if(mysql_fetch_row_format(Query, "|"))
{
mysql_fetch_field_row(string, "House ID"); h = strval(string);
printf("ID: %d", h);
}
mysql_free_result();
but it always returns ID: 0 instead 1 'cause my max house id is 1
Re: how to get max field in mysql -
Jefff - 05.01.2012
Why not
mysql_format(1, Query, "SELECT MAX(`House ID`) FROM `pf_houses`");
mysql_query(Query);
printf("Query: %s", Query);
mysql_store_result();
new h = mysql_fetch_int();
printf("ID: %d", h);
mysql_free_result();
and should be House_ID ? I think
Re: how to get max field in mysql -
Vince - 05.01.2012
Use this query:
Код:
SELECT `House ID` FROM `pf_houses` ORDER BY `House ID` DESC LIMIT 1;
Then use mysql_fetch_int to get the result.
Re: how to get max field in mysql -
System64 - 05.01.2012
@Jefff - With your code it doesn't work when I restar my server
@Vince - thanks, your works