Jump to content

Date Format


RidgeandGable

Recommended Posts

This is what I have in php 

Displaying the Field: 
<td><div align="center"><?php echo $row_Invoices['duebydate']; ?></div></td>
Select Statement
mysql_select_db($database_Harry, $Harry);
$query_Invoices = sprintf("SELECT * FROM invoices WHERE username = '%s' ORDER BY invoicedate DESC", $colname_Invoices);
$query_limit_Invoices = sprintf("%s LIMIT %d, %d", $query_Invoices, $startRow_Invoices, $maxRows_Invoices);
$Invoices = mysql_query($query_limit_Invoices, $Harry) or die(mysql_error());
$row_Invoices = mysql_fetch_assoc($Invoices);

How would I use your code in this?

Link to comment
Share on other sites

Thanks Sen

 

Have tried what you put but still puts the same error out

 


mysql_select_db($database_Harry, $Harry);
$query_Invoices = sprintf("SELECT id,username,DATE_FORMAT(invoicedate,%d-%m-%y) as date,DATE_FORMAT(duebydate,%d-%m-%y) as date,description,invoicenumber,download,paid,DATE_FORMAT(datepaid,%d-%m-%y) as date
         FROM invoices
         WHERE username = '%s'
         ORDER BY invoicedate DESC", $colname_Invoices);
$query_limit_Invoices = sprintf("%s LIMIT %d, %d", $query_Invoices, $startRow_Invoices, $maxRows_Invoices);
$Invoices = mysql_query($query_limit_Invoices, $Harry) or die(mysql_error());
$row_Invoices = mysql_fetch_assoc($Invoices);

This is row 20 -  ORDER BY invoicedate DESC", $colname_Invoices);

Warning: sprintf(): Too few arguments in C:\xampp\htdocs\rgroofing\Invoices.php on line 20
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 10' at line 1

Link to comment
Share on other sites

Well, yes. sprintf() is converting the %[identifiers], which mysql is also using. So don't use sprintf() when using those mysql functions that contain %[identifier]. If you use prepared statements for your queries, this will be a non-issue plus they are way better to use anyway.

Link to comment
Share on other sites

if you are going to use sprintf() to build your query string, you would need to double the %% in the DATE_FORMAT() format string so that they are treated as literal % instead of a sprintf() format specifier.

 

however, if you are using sprintf() to build your query strings, you might as well just switch to prepared queries. the %s, %d, ... sprintf() format specifiers are where you would put the prepared query place-holders, so all you would have to do is change them to ?, prepare the query, bind any input data (which are the argument(s) in the sprintf() statement), and execute the query.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.