10.11.2012, 04:47
Hello Everyone,
I want to get the highest value of a field in a MYSQL table.
I have this custom function to return the highest value of a field from the SQLite table. It works perfectly, Here is the function in SQLite:
My friend 'Ronaldo_raul™' helped me to code a new function for MYSQL. But it always return -1.
Is there anyone who can fix this function? so that it will return the Highest value of a field in a table??
Thank You
Ballu Miaa
I want to get the highest value of a field in a MYSQL table.
I have this custom function to return the highest value of a field from the SQLite table. It works perfectly, Here is the function in SQLite:
pawn Код:
stock sqlite_highest_field(DB:db, fieldname[], tablename[])
{
new querys[128], DBResult:qresult, id = -1, queryresult[128];
format(querys, sizeof(querys), "SELECT max( `%s` ) FROM `%s`", fieldname, tablename);
qresult = db_query(db, querys);
db_get_field(qresult,0,queryresult,128);
id = strval(queryresult);
db_free_result(qresult);
return id;
}
Is there anyone who can fix this function? so that it will return the Highest value of a field in a table??
pawn Код:
stock name ( fieldname [] , tablename [] )
{
new qry [ 128 ] , val = -1 ;
format( qry , 128 , "SELECT max( `%s` ) FROM `%s`" , fieldname , tablename ) ;
mysql_query ( qry ) ;
mysql_store_result ( ) ;
new rows = mysql_num_rows ( ) ;
mysql_free_result ( ) ;
if(!rows) return 0 ;
else return val ;
}
Ballu Miaa