MySql php pageview counter
Posted: Fri Nov 27, 2009 8:24 pm
Code: Select all
<?php
$con = mysql_connect("xxxx","xxxx","xxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$dbname = 'xxxx';
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM prizes")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Prize</th> <th>Views</th> </tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo $row['prize'];
echo "</td><td>";
echo $row['viewers'];
echo "</td></tr>";
echo "</table>";
$row['viewers'] = $viewers;
$newviewers = $viewers + 1;
mysql_query("UPDATE prizes SET viewers = $newviewers
WHERE prize = 'testprize'");
mysql_close($con);
}
?>Thank you.
You can see it in action here:
http://bit.ly/81ztLp