# top-10/1.1/top-10-addcount.js.php

WebberZone Top 10 — Popular Posts, version 1.1. 37 lines.

- Page: https://pluginprobe.com/plugins/top-10/1.1/code/top-10-addcount.js.php
- Raw: https://pluginprobe.com/plugins/top-10/1.1/raw/top-10-addcount.js.php
- Modified: 2009-02-16T07:44:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/top-10/1.1/code/top-10-addcount.js.php#L10-L20`.

```php
<?php
//"top-10-addcount.js.php" Add count to database
Header("content-type: application/x-javascript");

if (!function_exists('add_action')) {
	$wp_root = '../../..';
	if (file_exists($wp_root.'/wp-load.php')) {
		require_once($wp_root.'/wp-load.php');
	} else {
		require_once($wp_root.'/wp-config.php');
	}
}

// Ajax Increment Counter
tptn_inc_count();
function tptn_inc_count() {
	global $wpdb;
	$table_name = $wpdb->prefix . "top_ten";
	
	$id = intval($_GET['top_ten_id']);
	if($id > 0) {
		$results = $wpdb->get_results("select postnumber, cntaccess from $table_name where postnumber = '$id'");
		$test = 0;
		if ($results) {
			foreach ($results as $result) {
				$wpdb->query("update $table_name set cntaccess = cntaccess + 1 where postnumber = $result->postnumber");
				$test = 1;
			}
		}
		if ($test == 0) {
			$wpdb->query("insert into $table_name (postnumber, cntaccess) values('$id', '1')");
		}
	}
}

?>

```
