PHP: Pengiraan Jumlah Pengunjung


Salam, ni aku nak kongsikan coding untuk mengira jumlah pengujung ke website kita. boring beb!

step 1: Code yang ni letak atas sekali dalam page. Pastikan database dah buat.
session_start();
if(isset($_SESSION['ip3']))
{
mysql_select_db($database_connection, $connection);
$query_count = "SELECT * FROM `count`";
$count = mysql_query($query_count, $connection) or die(mysql_error());
$row_count = mysql_fetch_assoc($count);
$totalRows_count = mysql_num_rows($count);

$total = $row_count['total'];

}
else
{
mysql_select_db($database_connection, $connection);
$query_count = "SELECT * FROM `count`";
$count = mysql_query($query_count, $connection) or die(mysql_error());
$row_count = mysql_fetch_assoc($count);
$totalRows_count = mysql_num_rows($count);

$total = $row_count['total']+1;

include('connection.php');
$sql = "update count set total='$total' where id='$row_count[id]'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

$_SESSION['ip3'] = 1;
}


step 2: Dan yang ni code untuk display counter viewer. letak je tempat yang rasa korang suka.


if(strlen($total)==1) {echo "00000000".$total."";}
elseif(strlen($total)==2)
{echo "0000000".$total."";}
elseif(strlen($total)==3)
{echo "000000".$total."";}
elseif(strlen($total)==4)
{echo "00000".$total."";}
elseif(strlen($total)==5)
{echo "0000".$total."";}
elseif(strlen($total)==6)
{echo "000".$total."";}
elseif(strlen($total)==7)
{echo "00".$total."";}
elseif(strlen($total)==8)
{echo "0".$total."";}
elseif(strlen($total)==9)
{echo "".$total."";}


Ni sample yang aku buat:

POSTED BY juong

Popular Posts

.

Back to Top