Displaying content based on logged in status, and updating view count on a view

Using a customfield view field: http://drupal.org/project/views_customfield
<?php
global $user;
$content_to_display=$data->node_revisions_body;
 
if ($user->uid) {
         echo $content_to_display;
}
if (!$user->uid) {
echo substr($content_to_display,0,350);
echo " [...] <a href=\"/user/register\">Register</a> or <a href=\"/user/login\">log in</a>  to read more.";
}
?>
 
<?php
// Need to do this b/c statistics won't update from a view
// Based on statistics.module
// MPF Oct 19, 2009
// A node has been viewed, so update the node's counters.
      db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $data->nid);
      // If we affected 0 rows, this is the first time viewing the node.
      if (!db_affected_rows()) {
        // We must create a new row to store counters for the new node.
        db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $data->nid, time());
      }
?>