Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    please help limit unix_timestamp by last 7 days

    please could some one help me i need to limit the query by timestamp for the last 7 days here is my code on the php side

    Code:
     <?php
    			 
                 $db = @mysql_connect("localhost", "8conv", "*****") or die("Connection Error: " . mysql_error());
                 mysql_select_db("tempmonitor") or die("Error connecting to db.");
                 $sql = "SELECT *, UNIX_TIMESTAMP(datetime) AS datetime FROM 8conv";
                 $result = mysql_query($sql);
                 $data = array();
                 while ($row = mysql_fetch_array($result)) {
                    $temp1[] = array($row['datetime'] * 1000, (int)$row['temp1']);;
    				
                 }
                
    			 $temp1 = json_encode($temp1);

  • #2
    New Coder
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    80
    Thanks
    1
    Thanked 8 Times in 8 Posts
    I'd say create a variable that holds the timestamp of the soonest date you want to grab.

    So something like

    PHP Code:
    $oldest strtotime"-1 week" ); 
    Then update your SQL query to read

    PHP Code:
    $sql "SELECT *, UNIX_TIMESTAMP(datetime) AS datetime FROM 8conv WHERE UNIX_TIMESTAMP(datetime) > {$oldest}"

  • Users who have thanked Truffle for this post:

    chris666uk1 (11-17-2011)

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you so much that got it


  •  

    Posting Permissions

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