Copy link to clipboard
Copied
I'm attempting to format some date information. I'm taking the following query:
mysql_select_db($database_adventcms, $adventcms);
$query_rsDatedetails = sprintf("SELECT * FROM tbEvents WHERE id = %s", GetSQLValueString($colname_rsDatedetails, "int"));
$rsDatedetails = mysql_query($query_rsDatedetails, $adventcms) or die(mysql_error());
$row_rsDatedetails = mysql_fetch_assoc($rsDatedetails);
$totalRows_rsDatedetails = mysql_num_rows($rsDatedetails);
and changing it to this:
mysql_select_db($database_adventcms, $adventcms);
$query_rsDatedetails = sprintf("SELECT *, DATE_FORMAT(datestart, '%b') AS whichMonth, DATE_FORMAT(datestart, '%Y') AS whichYear, DATE_FORMAT(datestart, '%D') AS whichDate FROM tbEvents WHERE id = %s", GetSQLValueString($colname_rsDatedetails, "int"));
$rsDatedetails = mysql_query($query_rsDatedetails, $adventcms) or die(mysql_error());
$row_rsDatedetails = mysql_fetch_assoc($rsDatedetails);
$totalRows_rsDatedetails = mysql_num_rows($rsDatedetails);
When I run it I get this error:
Warning: sprintf() [function.sprintf]: Too few arguments in /home/iasindia/public_html/beta/newsandevents/eventdetails.php on line 60
Query was empty
which refers to the query line above. The odd thing is that same query works on a different query like this:
$query_rsDates = "SELECT *, DATE_FORMAT(datestart, '%b') AS whichMonth, DATE_FORMAT(datestart, '%Y') AS whichYear, DATE_FORMAT(datestart, '%D') AS whichDate FROM tbEvents WHERE status = 'Live' AND datestart >= CURDATE() ORDER BY datestart DESC";
$query_limit_rsDates = sprintf("%s LIMIT %d, %d", $query_rsDates, $startRow_rsDates, $maxRows_rsDates);
$rsDates = mysql_query($query_limit_rsDates, $adventcms) or die(mysql_error());
$row_rsDates = mysql_fetch_assoc($rsDates);
But I can't get it to work on the $query_rsDatedetails above.
Any help would be appreciated!
Copy link to clipboard
Copied
The sprintf function is interpreting the date format type as an input. There are several solutions:
http://stackoverflow.com/questions/5835534/mysql-query-date-format-and-sprintf