php ทำเว็บบอร์ดนับจำนวนคนเข้าและคนตอบกระทู้ครับ ตอนนี้ติดทำคนตอบด้วยครับ
php ทำเว็บบอร์ดนับจำนวนคนเข้าและคนตอบกระทู้ครับ
พอมีคนคลิกเข้ายอด ดูมันขึ้นแล้วครับแต่พอเวลาคนที่เข้าตอบกระทู้ มันกลายเป็นเพิ่ม 2 ยอดดูเลยอะครับ
ตอนนี้ยังเหลือคนตอบอ่ะครับตอบแล้วยอดไม่เพิ่ม รบกวนช่วยหน่อยนะครับ
ฐานข้อมูลนะครับ
Code
<?php require_once('Connections/work.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "admin";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "a_restric.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO ans (t_id, t_message, t_name, t_email, t_date, q_id) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['t_id'], "int"),
GetSQLValueString($_POST['t_message'], "text"),
GetSQLValueString($_POST['t_name'], "text"),
GetSQLValueString($_POST['t_email'], "text"),
GetSQLValueString($_POST['t_date'], "text"),
GetSQLValueString($_POST['q_id'], "int"));
mysql_select_db($database_work, $work);
$Result1 = mysql_query($insertSQL, $work) or die(mysql_error());
$insertGoTo = "a_webboard_ans.php?q_id=" . $row_quiz['q_id'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$objQuery = mysql_query($strSQL);
$maxRows_quiz = 10;
$pageNum_quiz = 0;
if (isset($_GET['pageNum_quiz'])) {
$pageNum_quiz = $_GET['pageNum_quiz'];
}
$startRow_quiz = $pageNum_quiz * $maxRows_quiz;
$colname_quiz = "-1";
if (isset($_GET['q_id'])) {
$colname_quiz = (get_magic_quotes_gpc()) ? $_GET['q_id'] : addslashes($_GET['q_id']);
}
mysql_select_db($database_work, $work);
$query_quiz = sprintf("SELECT * FROM quiz WHERE q_id = %s", $colname_quiz);
$query_limit_quiz = sprintf("%s LIMIT %d, %d", $query_quiz, $startRow_quiz, $maxRows_quiz);
$quiz = mysql_query($query_limit_quiz, $work) or die(mysql_error());
$row_quiz = mysql_fetch_assoc($quiz);
if (isset($_GET['totalRows_quiz'])) {
$totalRows_quiz = $_GET['totalRows_quiz'];
} else {
$all_quiz = mysql_query($query_quiz);
$totalRows_quiz = mysql_num_rows($all_quiz);
}
$totalPages_quiz = ceil($totalRows_quiz/$maxRows_quiz)-1;
$maxRows_ans = 10;
$pageNum_ans = 0;
if (isset($_GET['pageNum_ans'])) {
$pageNum_ans = $_GET['pageNum_ans'];
}
$startRow_ans = $pageNum_ans * $maxRows_ans;
$strSQL = "UPDATE quiz SET q_read = q_read + 1 WHERE q_id = '".$_GET["q_id"]."' ";
$objQuery = mysql_query($strSQL);
$strSQL = "SELECT * FROM quiz WHERE q_id = '".$_GET["q_id"]."' ";
$colname_ans = "-1";
if (isset($_GET['q_id'])) {
$colname_ans = (get_magic_quotes_gpc()) ? $_GET['q_id'] : addslashes($_GET['q_id']);
}
mysql_select_db($database_work, $work);
$query_ans = sprintf("SELECT * FROM ans WHERE q_id = %s ORDER BY t_id DESC", $colname_ans);
$query_limit_ans = sprintf("%s LIMIT %d, %d", $query_ans, $startRow_ans, $maxRows_ans);
$ans = mysql_query($query_limit_ans, $work) or die(mysql_error());
$row_ans = mysql_fetch_assoc($ans);
if (isset($_GET['totalRows_ans'])) {
$totalRows_ans = $_GET['totalRows_ans'];
} else {
$all_ans = mysql_query($query_ans);
$totalRows_ans = mysql_num_rows($all_ans);
}
$totalPages_ans = ceil($totalRows_ans/$maxRows_ans)-1;
$colname_admin = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_admin = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_work, $work);
$query_admin = sprintf("SELECT * FROM `admin` WHERE a_user = '%s'", $colname_admin);
$admin = mysql_query($query_admin, $work) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="0">
<tr>
<td>q_id</td>
<td>q_title</td>
<td>q_message</td>
<td>q_name</td>
<td>q_email</td>
<td>q_date</td>
<td>q_read</td>
<td>q_write</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_quiz['q_id']; ?></td>
<td><?php echo $row_quiz['q_title']; ?></td>
<td><?php echo $row_quiz['q_message']; ?></td>
<td><?php echo $row_quiz['q_name']; ?></td>
<td><?php echo $row_quiz['q_email']; ?></td>
<td><?php echo $row_quiz['q_date']; ?></td>
<td><?php echo $row_quiz['q_read']; ?></td>
<td> </td>
</tr>
<?php } while ($row_quiz = mysql_fetch_assoc($quiz)); ?>
</table>
<p> </p>
<table border="0">
<tr>
<td>t_id</td>
<td>t_message</td>
<td>t_name</td>
<td>t_email</td>
<td>t_date</td>
<td>q_id</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_ans['t_id']; ?></td>
<td><?php echo $row_ans['t_message']; ?></td>
<td><?php echo $row_ans['t_name']; ?></td>
<td><?php echo $row_ans['t_email']; ?></td>
<td><?php echo $row_ans['t_date']; ?></td>
<td><?php echo $row_ans['q_id']; ?></td>
</tr>
<?php } while ($row_ans = mysql_fetch_assoc($ans)); ?>
</table>
<p> </p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">T_message:</td>
<td><input type="text" name="t_message" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="t_id" value="">
<input type="hidden" name="q_id" value="<?php echo $_GET['q_id'];?>">
<input type="hidden" name="MM_insert" value="form1">
<input name="t_name" type="hidden" id="t_name" value="<?php echo $row_admin['a_name']; ?>" />
<input name="t_email" type="hidden" id="t_email" value="<?php echo $row_admin['a_email']; ?>" />
<input name="t_date" type="hidden" id="t_date" value="<?php echo date("j F Y H:i:s") ; ?>" />
</form>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($quiz);
mysql_free_result($ans);
mysql_free_result($admin);
?>
Tag : PHP
Date :
2012-09-26 02:20:13
By :
kupramza
View :
6222
Reply :
2
Load balance : Server 05