how to get max field in mysql
#1

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
Reply
#2

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
Reply
#3

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.
Reply
#4

@Jefff - With your code it doesn't work when I restar my server
@Vince - thanks, your works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)