时间:2021-07-01 10:21:17 帮助过:3人阅读
php教程 ajax 留言板
提供一款国人写的php ajax 留言板,他是利用了jquery php mysql教程 ajax来实现php ajax 局部刷新留方板实例的喜欢就下载吧。
*/
$link = @mysql_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection');
mysql_query("set names 'utf8'");
mysql_select_db($db_database,$link);
class comment
{
private $data = array();
public function __construct($row)
{
/*
/ the constructor
*/
$this->data = $row;
}
public function markup()
{
/*
/ this method outputs the xhtml markup of the comment
*/
// setting up an alias, so we don't have to write $this->data every time:
$d = &$this->data;
$link_open = '';
$link_close = '';
if($d['url']){
// if the person has entered a url when adding a comment,
// define opening and closing hyperlink tags
$link_open = '';
$link_close = '';
}
// converting the time to a unix timestamp:
$d['dt'] = strtotime($d['dt']);
// needed for the default gravatar image:
$url = 'http://'.dirname($_server['server_name'].$_server["request_uri"]).'/img/default_avatar.gif';
return '
'.$link_open.'
'.$link_close.'
'.$link_open.$d['name'].$link_close.'
'.date('d m y',$d['dt']).'
'.$d['body'].'
private static function validate_text($str)
{
/*
/ this method is used internally as a filter_callback
*/
if(mb_strlen($str,'utf8')<1)
return false;
// encode all html special characters (<, >, ", & .. etc) and convert
// the new line characters to
tags:
$str = nl2br(htmlspecialchars($str));
// remove the new line characters that are left
$str = str_replace(array(chr(10),chr(13)),'',$str);
return $str;
}
}
$comments = array();
$result = mysql_query("select * from comments order by id asc");
while($row = mysql_fetch_assoc($result))
{
$comments[] = new comment($row);
}
?>
/*
/ output the comments one by one:
*/
foreach($comments as $c){
echo $c->markup();
}
?>
add a comment
数据库教程结构
--
-- table structure for table `comments`
--
create table `comments` (
`id` int(10) unsigned not null auto_increment,
`name` varchar(128) collate utf8_unicode_ci not null default '',
`url` varchar(255) collate utf8_unicode_ci not null default '',
`email` varchar(255) collate utf8_unicode_ci not null default '',
`body` text collate utf8_unicode_ci not null,
`dt` timestamp not null default '0000-00-00',
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci;
源码下载
http://down.php100.com/down/code/php/liuyanboke/2010/1028/21479.html
http://www.bkjia.com/PHPjc/444830.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444830.htmlTechArticlephp ajax 留言板提供一款国人写的php ajax 留言板,他是利用了jquery php mysql ajax来实现php ajax 局部刷新留方板实例的喜欢就下载吧。 php教程 ajax...