Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

view counter php mysql?

Ads
banner
banner
banner
ivan Offline referral

Posts: 713
Joined: Jul 2013
Reputation: 6

#1
Senior Member
How can I count web page views using PHP that will store that data in my database SQL?
surenot Offline referral

Posts: 500
Joined: Jan 2014
Reputation: 16

#2
Senior Member
It's pretty easy @ivan Wink

1. Lets create a table in your database where all views will be stored and then polled from.

Code:
CREATE TABLE `counter` ( `counter` INT( 20 ) NOT NULL );
INSERT INTO counter VALUES (0);

2. Now lets create PHP code that will update that table each time someone views the page, and also the same code will retrieve the views value!

PHP Code:
<?php
 
// Connect Database 
 
mysql_connect("hostname""username""password") or die(mysql_error()); 
 
mysql_select_db("database_name") or die(mysql_error()); 

//Update Table
mysql_query("UPDATE counter SET counter = counter + 1");

//Retrieves count 
$views mysql_fetch_row(mysql_query("SELECT counter FROM counter"));

//Shows count
print "$views[0]"
?>
Rapidsoft technologies Offline referral

Posts: 209
Joined: Sep 2015
Reputation: 1

#3
Member
It can be done some other ways like just create table and follow the above procedure.





User(s) browsing this thread: 1 Guest(s)