Get node view count for each day I have site with thousands of user and logins each day. I need to track each page views of each user to generate a report.

If a user 'A' visits a page 'P' today, a new entry daycount is added
to the DB. If the same user 'A' visits the same page 'P' on same day,
the daycount will increment by one. If a user 'A' visits page 'P'
tomorrow, a new entry daycount is added to the DB.

I am using drupal 7. The insert and update works properly if there is no date comparison. Once i added  if($TimeNow &gt; $UpdateTime), the page load never ends. Can anyone help me to fix this.

if(db_query('SELECT daycount FROM {report_page_view} WHERE id = 9999999990 AND uid = :uid )', array(':uid' =&gt; $GLOBALS['user']-&gt;uid))-&gt;rowCount() == 0) {

    $ChQry = "(SELECT timestamp FROM {report_page_view} WHERE id = 9999999990 AND uid = :uid )', array(':uid' =&gt; $GLOBALS['user']-&gt;uid)"; // Get the previous timestamp
    $ChResult = db_query($ChQry);

    while ( $ChGetResult = $ChResult-&gt;fetchAssoc() ) {
       $TimeStm = $ChGetResult['timestamp']; 
    }   
        $UpdateTime = $TimeStm + 86400; //Get the next day 
        $TimeNow = time();
        if($TimeNow &gt; $UpdateTime) { // Compare current time and tomorrows date
        // insert if condition works
        $insert_page = db_insert('report_page_view')-&gt;fields(array('title', 'memberorg', 'id', 'type', 'timestamp', 'daycount', 'uid', 'fname', 'lname'));
            $insert_page-&gt;values(array(
            'title' =&gt; $Title,
            'memberorg' =&gt; $MemberOrg,
            'id' =&gt; 9999999990,
            'type' =&gt; 'views',
            'timestamp' =&gt; REQUEST_TIME,
            'daycount' =&gt; 1,
            'uid' =&gt; $UserId,
            'fname' =&gt; $FName,
            'lname' =&gt; $LName,

          ));               
        $insert_page-&gt;execute();
    }
    } // else update 
    db_update('report_page_view')
    -&gt;fields(array(
            'title' =&gt; $Title,
            'memberorg' =&gt; $MemberOrg,
            'id' =&gt; 9999999990,
            'type' =&gt; 'views',
            'timestamp' =&gt; REQUEST_TIME,
            'daycount' =&gt; 1,
            'uid' =&gt; $UserId,
            'fname' =&gt; $FName,
            'lname' =&gt; $LName,
    ))
    -&gt;expression('daycount', 'daycount + 1')`
Consider using the Node view count module for this. Here is a quote about it (from its project page, bold markup added here):

... allows to count node views. Unlike statistics module, this module records each view of node with user uid and timestamp. So now you can know how many times a user viewed node by day, week, month and etc.
This module is integrated with Views module. You can use it to create different statistics pages, output new not viewed nodes for user and many more.

By using this module, and to the extend it should be needed, you can then further refine / extend what you get (out-of-the-box) from this module via a custom module(s) and/or view(s).