2023年6月21日发(作者:)
Ajax新闻评论系统,带分页。
昨天在网上找了半天发现没什么好用的,于是干脆自己动手写了一个,希望对大家有所帮助。
测试环境:IIS5.1 + PHP5.2.12 + MySQL5.0.88
程序说明:本系统只是实现了基本的功能,其他的诸如数据过滤、数据编码和解码,后台审核功能等,根据需要加上就行了。为了测试方便,本程序没有对验证码进行判断。
特别提醒:本程序使用的是PDO,所以中的extension=php_和extension=php_pdo_必须打开。如果出现问题,请仔细检查各个页面的路径是否正确。另外某些字符会影响程序的执行,所以在使用的时候最好对数据进行编码。
新闻页面:
"/TR/xhtml1/DTD/">
新闻正文 |
|
js文件:
ajax_
/*
Design By Xinge At 2007-05-22
Demo:/test/ajax2/
*/
var please_wait = null;
function open_url(url, target) {
var link;
if (!mentById) return false;
if (please_wait != null) mentById(target).innerHTML = please_wait;
if (XObject) {
try{link = new ActiveXObject("P");}
catch(e){link = new ActiveXObject("P");}
} else if (pRequest) link = new XMLHttpRequest();
if (link == undefined) return false;
ystatechange = function() { response(link, url, target); }
("GET", url, true);
(null);
}
function response(link, url, target) {
//alert(tate + ' -- ' + target);
//alert(tate);
if (tate < 4) {
mentById(target).innerHTML = "
alt=''>载入中,请稍后...";
} else {
//mentById(target).innerHTML = ( == 200) ?
seText : "Ooops!! A broken link! Please contact the webmaster of this website and give
him the fallowing errorcode: " + ;
mentById(target).innerHTML = ( == 200) ?
seText : "Ooops!! A broken link!";
}
}
function set_loading_message(msg) {
please_wait = msg;
}
plun_
//*************************************************
function addplun(){
mentById("plunact").disabled = true;
var actdelay = "mentById('plunact').disabled = false";
setTimeout(actdelay,15000);
var username = mentById("username").value;
var userface = mentById("userface").value;
var pluncont = mentById("pluncont").value;
var verifcode = mentById("verifcode").value;
if (username=="") {
alert("用户名不能为空!");();
} else if (<=2 || >300) {
alert("字数应为5-300个!");();
} else {
open_url("plun_?act=add&newsid="+newsid+"&clname="+clname+"&verifcode="+verifcode+"&username="+username+"&userface="+userface+"&pluncont="+convtobr(pluncont),null);
}
getplun(1);
}
//*************************************************
function getplun(page){
open_url("plun_?act=get&newsid="+newsid+"&clname="+clname+"&page="+page,"plunshow");
}
//*************************************************
function convtobr(ss){ var r, re;
re = /r/g;
r = e(re, "
");
re = /n/g;
r = e(re, "
");
return(r);
}
//*************************************************
function showface(){
if(mentById("facebox").y=="none"){
mentById("facebox").y = "block";
} else {
mentById("facebox").y = "none";
}
}
//*************************************************
function chosface(face){
mentById("facepic").src = "plunface/"+face;
mentById("userface").value = face;
showface();
}
评论显示页:plun_
把这个单独放到一个文件中,主要是为了便于修改,如果新闻页面数量很多的话。
header("Content-type: text/html; charset=gbk");
?>
网友评论
我有话说
PHP后台处理页面:plun_
header("expires: mon, 26 jul 1997 05:00:00 gmt");
header("cache-control: no-cache, must-revalidate");
header("pragma: no-cache");
header("Content-type: text/html; charset=gbk");
require_once 'dblink_';
$act = empty($_GET['act']) ? 'get' : $_GET['act'];
$newsid = intval($_GET['newsid']);
$clname = $_GET['clname'];
$verifcode = $_GET['verifcode'];
$username = $_GET['username'];
$face = $_GET['userface'];
$plun = $_GET['pluncont'];
$addtime = date('Y-m-d H:i:s');
$shenhe = 1;
if($act=='get') {
if( isset($_GET['page']) ){ $page = intval( $_GET['page'] );
} else {
$page = 1;
}
$page_size = 2; //每页显示条数
$sql01 = 'select count(pid) as amount from zhfl_plun where newsid='.$newsid;
foreach ($dbh->query($sql01) as $row01) { $amount=$row01['amount']; }
if( $amount ){
if( $amount < $page_size ){ $page_count = 1; }
if( $amount % $page_size ){
$page_count = (int)($amount / $page_size) + 1;
} else {
$page_count = $amount / $page_size;
}
} else {
$page_count = 0;
}
$page_string = '共'.$amount.'条 '.$page.'⁄'.$page_count.' 页 ';
if( $page == 1 ){
$page_string .= '首页 | 上一页 | ';
} else {
$page_string .= "首页 | href='javascript:;' onclick='getplun(".($page-1).")'>上一页
}
if( ($page == $page_count) || ($page_count == 0) ){
$page_string .= '下一页 | 尾页';
} else {
$page_string .= "下一页 |
尾页";
}
$page_string .= ' 转到
$page_string .= "";
for ($pn=1;$pn<=$page_count;$pn++) { $goto .= ''; }
$page_string .= $goto;
$page_string .= "页";
$sql01='select * from zhfl_plun where newsid='.$newsid.' and shenhe=1 order by addtime
desc limit '.($page-1)*$page_size .', '.$page_size;
foreach ($dbh->query($sql01) as $row01) {
echo '
echo '
'; echo ' '.$row01['username'].' 发表于 '.$row01['addtime'].' '; echo ' '.$row01['plun'].' | '; echo 'border="0"> | ';
echo '
}
echo '
} elseif($act=='add') {
try {
$sql01="insert into zhfl_plun (newsid,clname,username,face,plun,addtime,shenhe)
values ('$newsid','$clname','$username','$face','$plun','$addtime','$shenhe')";
$dbh->beginTransaction();
$dbh->exec($sql01);
$dbh->commit();
} catch (Exception $e) {
$dbh->rollBack();
echo "Failed: " . $e->getMessage();
}
} else {
echo '不允许的操作';
}
?>
数据库连接:
dblink_
$dbhost = 'localhost';
$dbuser = 'yutiedun';
$dbpw = '11111111';
$dbname = 'yutiedun';
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpw);
$dbh->query("set names 'gbk'");
?> 数据表结构:
CREATE TABLE IF NOT EXISTS `zhfl_plun` (
`pid` int(11) unsigned NOT NULL auto_increment,
`newsid` int(10) unsigned NOT NULL,
`clname` varchar(10) NOT NULL,
`username` varchar(50) NOT NULL,
`face` varchar(10) NOT NULL default '',
`plun` text NOT NULL,
`addtime` datetime NOT NULL,
`shenhe` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk ;
2023年6月21日发(作者:)
Ajax新闻评论系统,带分页。
昨天在网上找了半天发现没什么好用的,于是干脆自己动手写了一个,希望对大家有所帮助。
测试环境:IIS5.1 + PHP5.2.12 + MySQL5.0.88
程序说明:本系统只是实现了基本的功能,其他的诸如数据过滤、数据编码和解码,后台审核功能等,根据需要加上就行了。为了测试方便,本程序没有对验证码进行判断。
特别提醒:本程序使用的是PDO,所以中的extension=php_和extension=php_pdo_必须打开。如果出现问题,请仔细检查各个页面的路径是否正确。另外某些字符会影响程序的执行,所以在使用的时候最好对数据进行编码。
新闻页面:
"/TR/xhtml1/DTD/">
新闻正文 |
|
js文件:
ajax_
/*
Design By Xinge At 2007-05-22
Demo:/test/ajax2/
*/
var please_wait = null;
function open_url(url, target) {
var link;
if (!mentById) return false;
if (please_wait != null) mentById(target).innerHTML = please_wait;
if (XObject) {
try{link = new ActiveXObject("P");}
catch(e){link = new ActiveXObject("P");}
} else if (pRequest) link = new XMLHttpRequest();
if (link == undefined) return false;
ystatechange = function() { response(link, url, target); }
("GET", url, true);
(null);
}
function response(link, url, target) {
//alert(tate + ' -- ' + target);
//alert(tate);
if (tate < 4) {
mentById(target).innerHTML = "
alt=''>载入中,请稍后...";
} else {
//mentById(target).innerHTML = ( == 200) ?
seText : "Ooops!! A broken link! Please contact the webmaster of this website and give
him the fallowing errorcode: " + ;
mentById(target).innerHTML = ( == 200) ?
seText : "Ooops!! A broken link!";
}
}
function set_loading_message(msg) {
please_wait = msg;
}
plun_
//*************************************************
function addplun(){
mentById("plunact").disabled = true;
var actdelay = "mentById('plunact').disabled = false";
setTimeout(actdelay,15000);
var username = mentById("username").value;
var userface = mentById("userface").value;
var pluncont = mentById("pluncont").value;
var verifcode = mentById("verifcode").value;
if (username=="") {
alert("用户名不能为空!");();
} else if (<=2 || >300) {
alert("字数应为5-300个!");();
} else {
open_url("plun_?act=add&newsid="+newsid+"&clname="+clname+"&verifcode="+verifcode+"&username="+username+"&userface="+userface+"&pluncont="+convtobr(pluncont),null);
}
getplun(1);
}
//*************************************************
function getplun(page){
open_url("plun_?act=get&newsid="+newsid+"&clname="+clname+"&page="+page,"plunshow");
}
//*************************************************
function convtobr(ss){ var r, re;
re = /r/g;
r = e(re, "
");
re = /n/g;
r = e(re, "
");
return(r);
}
//*************************************************
function showface(){
if(mentById("facebox").y=="none"){
mentById("facebox").y = "block";
} else {
mentById("facebox").y = "none";
}
}
//*************************************************
function chosface(face){
mentById("facepic").src = "plunface/"+face;
mentById("userface").value = face;
showface();
}
评论显示页:plun_
把这个单独放到一个文件中,主要是为了便于修改,如果新闻页面数量很多的话。
header("Content-type: text/html; charset=gbk");
?>
网友评论
我有话说
PHP后台处理页面:plun_
header("expires: mon, 26 jul 1997 05:00:00 gmt");
header("cache-control: no-cache, must-revalidate");
header("pragma: no-cache");
header("Content-type: text/html; charset=gbk");
require_once 'dblink_';
$act = empty($_GET['act']) ? 'get' : $_GET['act'];
$newsid = intval($_GET['newsid']);
$clname = $_GET['clname'];
$verifcode = $_GET['verifcode'];
$username = $_GET['username'];
$face = $_GET['userface'];
$plun = $_GET['pluncont'];
$addtime = date('Y-m-d H:i:s');
$shenhe = 1;
if($act=='get') {
if( isset($_GET['page']) ){ $page = intval( $_GET['page'] );
} else {
$page = 1;
}
$page_size = 2; //每页显示条数
$sql01 = 'select count(pid) as amount from zhfl_plun where newsid='.$newsid;
foreach ($dbh->query($sql01) as $row01) { $amount=$row01['amount']; }
if( $amount ){
if( $amount < $page_size ){ $page_count = 1; }
if( $amount % $page_size ){
$page_count = (int)($amount / $page_size) + 1;
} else {
$page_count = $amount / $page_size;
}
} else {
$page_count = 0;
}
$page_string = '共'.$amount.'条 '.$page.'⁄'.$page_count.' 页 ';
if( $page == 1 ){
$page_string .= '首页 | 上一页 | ';
} else {
$page_string .= "首页 | href='javascript:;' onclick='getplun(".($page-1).")'>上一页
}
if( ($page == $page_count) || ($page_count == 0) ){
$page_string .= '下一页 | 尾页';
} else {
$page_string .= "下一页 |
尾页";
}
$page_string .= ' 转到
$page_string .= "";
for ($pn=1;$pn<=$page_count;$pn++) { $goto .= ''; }
$page_string .= $goto;
$page_string .= "页";
$sql01='select * from zhfl_plun where newsid='.$newsid.' and shenhe=1 order by addtime
desc limit '.($page-1)*$page_size .', '.$page_size;
foreach ($dbh->query($sql01) as $row01) {
echo '
echo '
'; echo ' '.$row01['username'].' 发表于 '.$row01['addtime'].' '; echo ' '.$row01['plun'].' | '; echo 'border="0"> | ';
echo '
}
echo '
} elseif($act=='add') {
try {
$sql01="insert into zhfl_plun (newsid,clname,username,face,plun,addtime,shenhe)
values ('$newsid','$clname','$username','$face','$plun','$addtime','$shenhe')";
$dbh->beginTransaction();
$dbh->exec($sql01);
$dbh->commit();
} catch (Exception $e) {
$dbh->rollBack();
echo "Failed: " . $e->getMessage();
}
} else {
echo '不允许的操作';
}
?>
数据库连接:
dblink_
$dbhost = 'localhost';
$dbuser = 'yutiedun';
$dbpw = '11111111';
$dbname = 'yutiedun';
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpw);
$dbh->query("set names 'gbk'");
?> 数据表结构:
CREATE TABLE IF NOT EXISTS `zhfl_plun` (
`pid` int(11) unsigned NOT NULL auto_increment,
`newsid` int(10) unsigned NOT NULL,
`clname` varchar(10) NOT NULL,
`username` varchar(50) NOT NULL,
`face` varchar(10) NOT NULL default '',
`plun` text NOT NULL,
`addtime` datetime NOT NULL,
`shenhe` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk ;
发布评论