簡體   English   中英

每頁的瀏覽量

[英]Number of page views per page

誰能告訴我如何顯示用戶的(個人)頁面瀏覽量。 我的網站中有5個網頁,當我在所有頁面中放置以下php代碼時,它將顯示相同的頁面瀏覽量,而不是每頁瀏覽量。

注意; 我仍然是Web設計領域的新手。

這是我的代碼counter.php

<?php 

mysql_connect("localhost", "root", "root") or die(mysql_error());  mysql_select_db("myinfo_db") or die(mysql_error());
 mysql_query("UPDATE counter SET counter = counter + 1");


 $count = mysql_fetch_row(mysql_query("SELECT counter FROM counter"));


 echo "$count[0]";

?>

您的counter表應至少包含3列:ID,頁面和視圖。

因此,當用戶訪問時,可以說首頁,然后使用

mysql_query("UPDATE counter SET views = views + 1 WHERE page = 'homepage'");

然后,僅在顯示首頁視圖時,您可以使用:

mysql_query("SELECT views FROM counter WHERE page = 'homepage'");

希望對您有所幫助。

您必須指定要增加頁面數的頁面。 您的表格應類似於:id-主鍵和計數器-當前頁數

每個頁面將被分配一個唯一的ID,並且所有操作都將針對該ID進行。 例如:

$currentPageId = 1; // let's say this is index.php, for other pages you have 2, 3 and so on
// update page count for the current page
mysql_query("UPDATE `counter` SET `counter` = `counter` + 1 WHERE `id` = $currentPageId");

// fetch the page count for the current page
$count = mysql_fetch_row(mysql_query("SELECT `counter` FROM `counter` WHERE `id` = $currentPageId"));

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM