adding a view count (my query)
-
I’ve added the following code into the main index.php file:
“<?php
// database information
$host = ‘localhost’;
$user = ‘myusername’;
$password = ‘mypw’;
$dbname = ‘wordpress’;// connect and select the database
$conn = mysql_connect($host, $user, $password) or die(mysql_error());
$db = mysql_select_db($dbname, $conn) or die(mysql_error());// select the view count
$sql = “select views from petersub_views”;
$result = mysql_query($sql, $conn) or die(mysql_error());// retrieve the view count and add 1
$list = mysql_fetch_array($result);
$new_postcount = $list[‘views’] + 1;// insert new entry into database
$sql = “update petersub_views set views = $new_postcount”;
$result = mysql_query($sql, $conn) or die(mysql_error());
?><?php
/* Short and sweet */
define(‘WP_USE_THEMES’, true);
require(‘./wp-blog-header.php’);
?>”Basically I just created a separate table to store the view count. In this code it increments the view count by 1, but for some reason it’ll increment by 2 or 3 on each page load and I have no idea why.
- The topic ‘adding a view count (my query)’ is closed to new replies.