Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make counting of hits

Status
Not open for further replies.

shop73

IS-IT--Management
May 13, 2007
48
0
0
BA
How to make counting of hits about products?

PHP-MySQL

In detail page I need to write: This product have ... hits!
 
EErgghhh !
Hit counters, Very 1990s [smile]

code as sqltrack.php
Code:
<?php
session_start();

function hitcount($page) {
$page =  "'" . substr($page,0) . "'" ;
if (!isset($_SESSION[$page])) {
	$_SESSION[$page] = true;
$db = mysql_connect("mysql_server", "username", "password");
mysql_select_db("db_name", $db);
$sql ="SELECT * FROM counter WHERE pageid=$page";
$result = mysql_query($sql);
$dbrow = mysql_fetch_array($result);
// check if any value was returned then update or new 

if (is_null($dbrow[2])) {
$sql = "INSERT INTO counter (pageid,hitcount) VALUES ($page,1)";
} else {
$dbrow[2] = $dbrow[2] + 1;
$sql = "UPDATE counter SET hitcount='$dbrow[2]' WHERE pageid = $page";
}
$result = mysql_query($sql);
$count = $dbrow[2];
mysql_close($db);
return $count;
}
}
?>

Table needs two columns
pageid: varchar(255)
hitcount: int unsigned

And in the page to be counted BEFORE ANY OTHER CODE.

Code:
<?php

include('include/sqltrack.php');
$count = hitcount($_SERVER['PHP_SELF']);
?>

then display $count wherever you need to.

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
How to make this?

I have master and detail page.

Master page (lists products):

- product1
- product2
- product3

Details page (show detail about one product whick we click on master page):

example:

- product1

This product have 100 views!

How to make count on detail page for all products?



 
I pass with URL parametar ProdID from Master to Detail page.

Table ProductCount:
pageid: varchar(255)
hitcount: int unsigned

Which code to put on Master page and Detail page to show views: or counting product for that product (unique ProdID)?








 
In table "products" I have ProdID, prodName, prodHits.

I pass with URL parametar ProdID from Master to Detail page. Now I need UPDATE prodHits when open detail page.
 
instead of
Code:
<?php

include('include/sqltrack.php');
$count = hitcount($_SERVER['PHP_SELF']);
?>
(From earlier post)

use
Code:
<?php

include('include/sqltrack.php');
$count = hitcount($prodID);
?>



Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top