Web Analytics Made Easy -
StatCounter MySQL DATE and DATE_SUB functions - CodingForum

Announcement

Collapse
No announcement yet.

MySQL DATE and DATE_SUB functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL DATE and DATE_SUB functions

    I tried to fix mysql_query, my server has MySQL 5.6

    This is the old code:

    PHP Code:
    $temp mysql_query("SELECT id FROM ".C_MYSQL_TEMP." WHERE date < DATE_SUB(NOW(), INTERVAL ".C_REG_DAYS." DAY)"); 
    I tried to fix this code by replacing "" with '', but still unable to fix:

    PHP Code:
    $temp mysql_query("SELECT id FROM '.C_MYSQL_TEMP.' WHERE date < DATE_SUB(NOW(), INTERVAL '.C_REG_DAYS.' DAY)"); 
    Can anyone see mistakes on this code?

  • #2
    There is nothing technically wrong with the original sql query syntax or the php string syntax building the sql query statement. By changing it, you have now introduced an sql query error since the defined constants for the table name and the number of days are no longer being treated as defined constants.

    If this code/query is not working, it's not due to the sql query statement.

    In reply #4 in your previous thread, you were advised to add some query error checking after each mysql_query(). Did you follow that advice?

    You should also set php's error_reporting to E_ALL and display_errors to ON so that php will help you by reporting and displaying all the errors it detects.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

    Comment


    • #3
      Yes I removed "@" before all the mysql queries and added "var_dump(mysql_error());"

      But I didn't see any error message.

      Now I added "error_reporting(E_ALL);" it doesn't show errors on page.
      Any changes need in php.ini?
      Last edited by arunasl; Oct 4, 2016, 03:07 AM.

      Comment


      • #4
        Change your code to
        PHP Code:
        echo $sql="SELECT id FROM ".C_MYSQL_TEMP." WHERE date < DATE_SUB(NOW(), INTERVAL ".C_REG_DAYS." DAY)"
        $temp mysql_query($sql) or die(mysql_error()); 
        and post the output.
        Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

        Comment


        • #5
          Originally posted by arunasl View Post
          Yes I removed "@" before all the mysql queries and added "var_dump(mysql_error());"

          But I didn't see any error message.
          Are you sure the php code is even running? Have you echoed anything on the page and you get the output from the echo statement?

          Originally posted by arunasl View Post
          Now I added "error_reporting(E_ALL);" it doesn't show errors on page.
          Did you also set display_errors to ON? You cannot just do part of the things we are suggesting.

          Lastly, in your previous thread, I asked you to tell us or show us what result you are getting that leads you to believe that something isn't working. For all we know your code isn't running at all or it is running but there's no matching data in the database for it to find and display.
          Last edited by CFMaBiSmAd; Oct 4, 2016, 08:03 AM.
          Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

          Comment

          Working...
          X