Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2014
    Posts
    35

    Unanswered: Query error with date format

    I am working on a database in php/mysql and have a table 'clientnotes' which has fields noteid, dateadded, addedby, note, clientcode. I want to see a simple table of all of the notes added for a specific client.

    If I use the query:
    $colname_rsNotes = "-1";
    if (isset($_GET['clientcode'])) {
    $colname_rsNotes = $_GET['clientcode'];
    }
    mysql_select_db($database_renmms, $renmms);
    $query_rsNotes = sprintf("SELECT noteid, dateadded, addedby, note, clientcode FROM clientnotes WHERE clientcode = %s", GetSQLValueString($colname_rsNotes, "text"));
    $rsNotes = mysql_query($query_rsNotes, $renmms) or die(mysql_error());
    $row_rsNotes = mysql_fetch_assoc($rsNotes);
    $totalRows_rsNotes = mysql_num_rows($rsNotes);

    then it works fine. However, if I add into it some code to format the date as below:

    $colname_rsNotes = "-1";
    if (isset($_GET['clientcode'])) {
    $colname_rsNotes = $_GET['clientcode'];
    }
    mysql_select_db($database_renmms, $renmms);
    $query_rsNotes = sprintf("SELECT noteid, dateadded, addedby, note, clientcode, DATE_FORMAT(dateadded,'%D %M %Y') AS formattedDate FROM clientnotes WHERE clientcode = %s", GetSQLValueString($colname_rsNotes, "text"));
    $rsNotes = mysql_query($query_rsNotes, $renmms) or die(mysql_error());
    $row_rsNotes = mysql_fetch_assoc($rsNotes);
    $totalRows_rsNotes = mysql_num_rows($rsNotes);

    Then I get a blank page except for 'Query was empty'

    What am I doing wrong?

    Many thanks.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    So what value is the value of $query_notes
    The place holders forthe dateadd function are notgoing to sit well wit sprintf. In fact I dont see why you are using sprintf at all

    you are assigning a numeric value using a string in = "-1"
    I dont know if that will cause problems but if its a numeric drop the "
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •