number of times page viewed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
s4salman
Forum Newbie
Posts: 7
Joined: Wed Nov 07, 2007 9:03 am

number of times page viewed

Post by s4salman »

i m using this script which shows data from mysql.I have one field named "count"
what i want to do this is to add 1 to this field every time page is loaded.field id is passed from a php page to this page.
http://funxy.com/bsongs-details.php?id=75

i just use sql to print records using this id from mysql database.Now i want this page to add 1 to field "count"

plz help no one is answering this to me.


i use this mysql page to connect.Plz write simple php code that just tell me how to update this field.nothing other code please as i only want to learn it.


Code: Select all

<?php
//mysql info !
$username ="v2073_v2073";
$password ="alpha123";
$databasename ="v2073_test";
$host ="localhost";

//admin login info !
$LOGIN_INFORMATION = array(
'v2073' => 'shell101'
);
?>
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Hi,

Its rather simple really.

Here is an example:

Code: Select all

$checkLog=mysql_query("SELECT * FROM table_name WHERE id_field='$id'");  //QUERY DATABASE AND QUERY WHETHER A LOG HAS BEEN PREVIOUSLY MADE
					
	if(mysql_num_rows($checkLog)>0)
	{
             //IF A PREVIOUS LOG HAS BEEN MADE THEN INCREMENT LOG COUNTER
		$logUpdate=mysql_query("UPDATE table_name SET count_field=count_field+1 WHERE id_field='$id'");
						
	} else {
	     //IF NO PREVIOUS LOG HAS BEEN MADE THEN INSERT NEW LOG AS 1
		$logCount=mysql_query("INSERT INTO table_name VALUES('$id', 1)");
	}
Post Reply