帖子列表的显示是一个基本的功能,用于首页分类的显示,以及用户收藏以及发布的帖子的查看.整合在一个文件里面.
接受参数:
col:收藏的帖子
c:分类显示帖子
post:发表的帖子
rep:回复的评论
templates/listview.php
返回
<?php echo $from ?>
发帖
//Chromephp::log($article);
if ($_GET['col'] || $_GET['c'] || $_GET['fav'] || $_GET['post'])
{
while ($article=mysql_fetch_array($query2))
{
$uid=$article['uid'];
$query1=mysql_query("select * from users where id='$uid'");
$user=mysql_fetch_array($query1);
$time=showtime($article['edittime']);
echo '
',$article['title'],'
',$user['name'],'
',$time,'
';// Chromephp::log($article);
}
mysql_free_result($query2);
}
else if($_GET['rep'] || $_GET['rep_new'])
{
while ($comment_=mysql_fetch_array($query2))
{
$query1=mysql_query("select name from users where id='$uid'");
$toname=mysql_fetch_array($query1);
$cuid=$comment_['uid'];
$query1=mysql_query("select name, cover from users where id='$cuid'");
$commenter=mysql_fetch_array($query1);
//Chromephp::log($comment_);
$ctime=showtime($comment_['addtime']);
echo '
',$commenter['name'],' 回复 ',$toname['name'],':
',$comment_['content'],'
',$ctime,'
回复
}
mysql_free_result($query);
}
?>
if ($p <= $pagenum-1)
{
# code...
$p += 1;
if($_GET['c'])
echo '下一页';
if($_GET['col'])
echo '下一页';
if($_GET['rep'])
echo '下一页';
if($_GET['rep_new'])
echo '下一页';
}
?>
listview.php
include('conn.php');
include('lib.php');
include('ChromePhp.php');
//使用会话内存储的变量值之前必须先开启会话
session_start();
// Chromephp::log($_SESSION['uid']);
// Chromephp::log($_SESSION['name']);
//如果会话没有被设置,查看是否设置了cookie
if(!isset($_SESSION['uid']))
{
if(isset($_COOKIE['uid'])&&isset($_COOKIE['name']))
{
//用cookie给session赋值
$_SESSION['uid']=$_COOKIE['uid'];
$_SESSION['name']=$_COOKIE['name'];
}
}
//获取用户id
$uid=$_SESSION['uid'];
//对于浏览器的get请求进行处理
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
//如果浏览器请求
if($_GET['c'])
{
//获取板块分类及文章数量
$c=$_GET['c'];
$sql="select name from categories where id='$c'";
$query=mysql_query($sql);
$node=mysql_fetch_assoc($query);
$from=$node['name'];
$count_result = mysql_query("SELECT count(*) as count FROM articles where category = '$from'");
$count_array = mysql_fetch_array($count_result);
//计算总的页数
$pagenum=ceil($count_array['count']/$pagesize);
//确定当前页数 $p 参数
$p = $_GET['p']?$_GET['p']:1;
//数据指针
$offset = ($p-1)*$pagesize;
$sql="select * from articles where category = '$from' ORDER BY edittime DESC LIMIT $offset, $pagesize ";
$query2=mysql_query($sql);
//Chromephp::log($query2);
include('templates/listview.php');
}
if ($_GET['post']==1)
{
//获取用户发表文章列表
$from="我发表的逗贴";
$count_result = mysql_query("SELECT count(*) as count FROM articles where uid='$uid'");
$count_array = mysql_fetch_array($count_result);
//计算总的页数
$pagenum=ceil($count_array['count']/$pagesize);
//确定当前页数 $p 参数
$p = $_GET['p']?$_GET['p']:1;
//数据指针
$offset = ($p-1)*$pagesize;
$sql="select * from articles where uid='$uid' ORDER BY edittime DESC LIMIT $offset, $pagesize ";
$query2=mysql_query($sql);
//Chromephp::log($query2);
include('templates/listview.php');
}
if ($_GET['col']==1)
{
//获取用户收藏文章列表
$from="我收藏的逗贴";
$count_result = mysql_query("SELECT count(*) as count FROM collects where uid='$uid'");
$count_array = mysql_fetch_array($count_result);
//计算总的页数
$pagenum=ceil($count_array['count']/$pagesize);
//确定当前页数 $p 参数
$p = $_GET['p']?$_GET['p']:1;
//数据指针
$offset = ($p-1)*$pagesize;
$sql="select articles.id, articles.title from articles, collects where articles.uid=collects.uid and collects.uid='$uid' ORDER BY collects.time DESC LIMIT $offset, $pagesize ";
$query2=mysql_query($sql);
//Chromephp::log($query2);
include('templates/listview.php');
}
if ($_GET['rep']==1)
{
//获取用户回复列表
$from="收到的回复";
$count_result = mysql_query("select count(*) as count from comments where touid='$uid'");
$count_array = mysql_fetch_array($count_result);
//计算总的页数
$pagenum=ceil($count_array['count']/$pagesize);
//确定当前页数 $p 参数
$p = $_GET['p']?$_GET['p']:1;
//数据指针
$offset = ($p-1)*$pagesize;
//获取对用户的回复和回复者的信息
$sql="select * from comments where touid = '$uid' ORDER BY addtime ASC LIMIT $offset, $pagesize";
$query2=mysql_query($sql);
//Chromephp::log($query2);
include('templates/listview.php');
}
if ($_GET['rep_new']==1)
{
//获取用户回复列表
$from="新的回复";
$count_result = mysql_query("select count(*) as count from comments where touid='$uid' and view=0");
$count_array = mysql_fetch_array($count_result);
//计算总的页数
$pagenum=ceil($count_array['count']/$pagesize);
//确定当前页数 $p 参数
$p = $_GET['p']?$_GET['p']:1;
//数据指针
$offset = ($p-1)*$pagesize;
$sql="select * from comments where touid = '$uid' ORDER BY addtime ASC LIMIT $offset, $pagesize";
$query2=mysql_query($sql);
//Chromephp::log($query2);
include('templates/listview.php');
}
}
?>