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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple hit counter problems

Status
Not open for further replies.

SLMHC

MIS
Jul 23, 2004
274
CA
ive been trying to get this script for work for a few days now.

<?php

include 'dbinfo.php';
include 'dbconnect.php';

//get count
$query = "SELECT * FROM counter";
$display=mysql_query($query);

$hits = $display;

if (!session_is_registered("counted"))
{
mysql_query("UPDATE counter SET hits = hits +1");
session_register("counted");
}

mysql_close();
}

It will not update the counter...help!

-Dave
 
well, as far as the sql is concerned, your UPDATE statement is fine

perhaps you should be asking in the php forum

r937.com | rudy.ca
 
thats the thing...i can run the sql statement in phpmyadmin and it works on the counter...but running this from the web produces nothing...ill try in the php forum...thanks

-Dave
 
Code:
<?php

include 'dbinfo.php';
include 'dbconnect.php';

//get count
$query = "SELECT * FROM counter";
$hits=mysql_query($query);

if (!session_is_registered("counted"))
	{
	mysql_query("UPDATE counter SET hits = hits +1");
	session_register("counted");
	}

mysql_close();

?>
Now my question turns back to sql...how do I get the value of the counter? mysql_numrows is not what I want...

-Dave
 
You could use mysql_fetch_array to get the value of the 'hits' table field.

Code:
<?php

include 'dbinfo.php';
include 'dbconnect.php';

//get count
$query = "SELECT * FROM counter";
$result=mysql_query($query);

if (!session_is_registered("counted"))
    {
    mysql_query("UPDATE counter SET hits = hits +1");
    session_register("counted");
    }
 
$row = mysql_fetch_array($result);
$hits = $row['hits'];
 
mysql_close();

?>
 
SLMHC said:
Now my question turns back to sql...how do I get the value of the counter?
why do you need it?


and do you want it before the update, or after?

by the way, it's still a php, not an sql question

:)

r937.com | rudy.ca
 
fetching the data in the row after checking if a session is registered would be best.

this is what I came up with after some more digging...

Code:
<?php

include 'dbinfo.php';
include 'dbconnect.php';

//get count
$query = "SELECT * FROM counter";
$hits=mysql_query($query);

$the_count = mysql_result($hits, 0);

if (!session_is_registered("counted"))
	{
	mysql_query("UPDATE counter SET hits = hits +1");
	session_register("counted");
	}

mysql_close();

?>

-Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top