I want to use sprintf() along with date_format in a MySQL query.
Here is query:
mysql_select_db($database_exdb, $expdb);
$query_eventeditrs = sprintf("SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'), timeofe开发者_如何学Pythonvent, location, details, presenter, bio FROM events WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
I am getting error that :
“Warning: sprintf() [fun
ction.sprintf]: Too few arguments. Query was Empty”
Plz help
You have to escape the date format string with extra %'s, try this:
sprintf("SELECT eventid, groupid, title,
DATE_FORMAT(dateofevent, '%%W, %%M %%d, %%Y'),
ti meofevent, location, details, presenter, bio
FROM events
WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
You need to actually run the query using mysql_query() see http://php.net/manual/en/function.mysql-query.php
In the sprintf string you have:
"SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'),
timeofevent, location, details, presenter,
bio FROM events WHERE eventid = %s"
Which has 5
inputs, but you only put in one (GetSQLValueString($colname_eventeditrs, "int")
), put in 4 more and you should be golden (or as said below in the comments, escape 4 of the inputs and that should also work)
精彩评论