网站开发-php开发手机论坛(10)-帖子列表显示

帖子列表的显示是一个基本的功能,用于首页分类的显示,以及用户收藏以及发布的帖子的查看.整合在一个文件里面.

接受参数:

col:收藏的帖子

c:分类显示帖子

post:发表的帖子

rep:回复的评论

templates/listview.php

<!DOCTYPE html>
<html>
<head>
<?php header("Content-type: text/html; charset=utf-8");  ?>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>


<script type="text/javascript">

</script>
</head>
<body>



	<div data-role="page" id="listview">
		<div data-role="header">
			<a class="ui-btn-left ui-icon-back ui-btn  ui-btn-inline ui-mini ui-corner-all ui-btn-icon-left "  data-rel="back" >返回</a>
			<h1><?php echo $from ?></h1>
			<a href="create.php" class="ui-btn-right ui-icon-plus ui-btn  ui-btn-inline ui-mini ui-corner-all ui-btn-icon-right ">发帖</a>
		</div>

		<div role="main" class="ui-content">
			<div class="content-primary">	
				<ul data-role="listview" data-inset="true" >
					<?php
					//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 '<li><a href="view.php?a=',$article['id'],'">
							<img src="',$user['cover'],'">
							<h3>',$article['title'],'</h3>
							<p>',$user['name'],'</p>
							<p>',$time,'</p>
							</a>
							</li>';
							// 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 '<li>
									<img src="',$commenter['cover'],'"><p>',$commenter['name'],' 回复 ',$toname['name'],': 
									',$comment_['content'],'</p>
									<p>',$ctime,' </p>
									<div>
									<a href="dialog.php?a=',$aid,'&touid=',$comment_['uid'],'" class="ui-btn ui-btn-inline ui-mini ui-icon-comment ui-btn-right ui-btn-icon-right ">回复</a>
									</div>
								</li>';

						}
						mysql_free_result($query);
					}
						
					?>
				</ul>
			</div>	
			<?php 
					if ($p <= $pagenum-1)
					{
						# code...
						$p += 1;
						if($_GET['c'])
							echo '<a  class="ui-btn  ui-btn-inlineui-corner-all" href="listview.php?c=',$c,'&p=',$p,'" >下一页</a>';
						if($_GET['post'])
							echo '<a  class="ui-btn  ui-btn-inlineui-corner-all" href="listview.php?post=1&p=',$p,'" >下一页</a>';
						if($_GET['col'])
							echo '<a  class="ui-btn  ui-btn-inlineui-corner-all" href="listview.php?col=1&p=',$p,'" >下一页</a>';
						if($_GET['rep'])
							echo '<a  class="ui-btn  ui-btn-inlineui-corner-all" href="listview.php?rep=1&p=',$p,'" >下一页</a>';
						if($_GET['rep_new'])
							echo '<a  class="ui-btn  ui-btn-inlineui-corner-all" href="listview.php?rep_new=1&p=',$p,'" >下一页</a>';
					} 
			?>
		</div>
	</div>
</body>
</html>

listview.php


<?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');
		}


	}

 ?>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值