伙计们,我在这里需要有关此代码的帮助..这是一个计数器代码..它工作正常,但不是我想要的工作方式。问题是当我编写另一个代码时,我简单地更改了页面名称,但问题是,假设第一页达到了10个视图,第二页将低于10,而它不会超过10。我尝试更改ON DUPLICATE KEY UPDATE,但是我没有得到我需要的结果,请帮助下面的代码...
<?php
function visitor($record) {
$db_host = "localhost";
$db_username = "username";
$db_password = "password";
$db_name = "database-name";
$db_table = "table-name";
$counter_page = "access_page";
$counter_field = "access_counter";
$db = mysqli_connect ($db_host, $db_username,
$db_password, $db_name) or die("Host or database not
accessible");
$sql_call = "INSERT INTO ".$db_table."
(".$counter_page.",
".$counter_field.") VALUES ('".$record."', 1) ON
DUPLICATE
KEY UPDATE ".$counter_field." = ".$counter_field." + 1";
mysqli_query($db, $sql_call) or die("Error while
entering");
$sql_call = "SELECT ".$counter_field. " FROM
".$db_table."
WHERE ".$counter_page. " = '".$record. "'";
$sql_result = mysqli_query($db, $sql_call) or die("SQL
request failed ");
$row = mysqli_fetch_assoc($sql_result);
$x = $row[$counter_field];
mysqli_close($db);
return $x;
}
?>
<?php
$page_name = "pictures";
$access_number = visitor($page_name);
echo $access_number;
?>