Posts: 54
Threads: 19
Joined: Apr 2013
Reputation:
0
Hi!
I want to use a function for mysql_query something like Function("UPDATE players SET money=%s where id=%d",name,id);
Can I make something like this?
I tried all what i know...
Posts: 1,648
Threads: 482
Joined: Jun 2010
pawn Код:
new query[256];
format(query, sizeof(query), "UPDATE %s SET %s = %d WHERE id = %d LIMIT 1", tablename, fieldname, value, sqlid);
mysql_query(query);
It's simple, just create a string, format it and query it!
You can also replace the '%s' %d etc with actual values.
Of course if you need to retrieve them, do it like you would in a string.
Have fun dude!
Posts: 54
Threads: 19
Joined: Apr 2013
Reputation:
0
You didn't understand what i want ...
I must to be more explicit...
I want a stock who combine mysql_format and mysql_query...
To execute query you must write only the query....
Function("UPDATE players SET age=%d where id=%d" age,id);
Posts: 1,648
Threads: 482
Joined: Jun 2010
pawn Код:
MySQL_SetInteger(sqlid, fieldname[], value, tablename[])
{
new query[256];
format(query, sizeof(query), "UPDATE %s SET %s = %d WHERE id = %d LIMIT 1", tablename, fieldname, value, sqlid);
return mysql_query(query);
}
Posts: 1,648
Threads: 482
Joined: Jun 2010
No problem, but I'd advise only to use this when updating a single value.
It may cause lag if used excessively.
Posts: 1,648
Threads: 482
Joined: Jun 2010
To limit the query to one update.