Jump to content

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
https://forums.phpfreaks.com/topic/292619-date-format/#findComment-1497204
Share on other sites


$query_Invoices = sprintf("SELECT id,username,InvoiceNumber,DATE_FORMAT(invoicedate,%d-%m-%y) as date
         FROM invoices
         WHERE username = '%s'
         ORDER BY invoicedate DESC", $colname_Invoices);
Link to comment
https://forums.phpfreaks.com/topic/292619-date-format/#findComment-1497216
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

Edited by RidgeandGable
Link to comment
https://forums.phpfreaks.com/topic/292619-date-format/#findComment-1497219
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
https://forums.phpfreaks.com/topic/292619-date-format/#findComment-1497221
Share on other sites

Sorry, I copied your code in my last post. The format definition should be in quotes, as in my original post (#4)

 

DATE_FORMAT(invoicedate,'%d-%m-%y').

 

And don't give them all the same alias (" as date") as you cannot then access them with $row['date']

Link to comment
https://forums.phpfreaks.com/topic/292619-date-format/#findComment-1497224
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
https://forums.phpfreaks.com/topic/292619-date-format/#findComment-1497328
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.