0
다음 스크립트는 데이터베이스를 업데이트하지만 각 페이지마다 정확한 페이지 수를 표시하지 않습니다. 그것은 어떤 이유로 대부분의 시간에 페이지의 페이지 수를 고정시킵니다. 여기 PHP와 MySQL은 여러 페이지 카운터 문제를 해결합니까?
는 PHP 코드 :<?php
$page = $_SERVER['SCRIPT_FILENAME'];
// Query member data from the database and ready it for display
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT id page FROM mysql_counter_logs WHERE page = '$page'");
if (mysqli_num_rows($dbc) == 0) {
$mysqli = new mysqli("localhost", "root", "", "sitename");
$clean_page = mysqli_real_escape_string($mysqli, $page);
$dbc = mysqli_query($mysqli,"INSERT INTO mysql_counter_logs (page) VALUES ('$clean_page')");
}
if ($dbc == 1) {
$dbc = mysqli_query($mysqli,"UPDATE mysql_counter_logs SET hits = hits + 1 WHERE page = '$page'");
}
//Retrieves the current count
$count = mysqli_fetch_row(mysqli_query($mysqli,"SELECT hits FROM mysql_counter_logs"));
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error();
}
//Displays the count on your site
echo $count[0];
?>
여전히 같은 문제를 얻을. – new
및 데이터베이스가 잘못 업데이트됩니다. – new