使用php显示三列中的帖子。 [英] Displaying posts in three columns using php.

查看:61
本文介绍了使用php显示三列中的帖子。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码显示了我的数据库中三列的帖子。最初我打电话给6个帖子,所以如果数据库帖子中有4个或5个帖子会占用表格中的列,并且有空缺少的帖子(工作正常)。现在我添加了更多ajax代码,这是长代码所以我不在这里发布。现在,如果我的数据库中有7个帖子,当我加载更多帖子来调用第7个帖子时它将覆盖整个表格,而不是它应该覆盖表格中一个列的空间,如果有两个空格怎么办?



 <?php  
$ sql = SELECT * FROM posts WHERE status ='active'ORDER BY id desc LIMIT 6;
$ query = $ db-> prepare($ sql);
$ query-> execute();
$ row = $ query-> fetch(PDO :: FETCH_ASSOC);
?>



 <      cellpadding   =  5    cellspacing   =  2 >  
< tr >
<? php do {
// 水平循环
?>
< span class =code-keyword>< td' >
< div > < h2 > < a href = blog.php?blogId =<?php echo $ row ['blogs_id']?> > <? php echo $ row [' title']; ?> < / a < span class =code-keyword>> < / h2 > < / div >
< div > < img src =' < ?php echo $ row [' pic']; > '> < / div >
< < span class =code-leadattribute> div > < h3 > <? php echo $ row [' posted']; ?> < / h3 < span class =code-keyword>> < / div > < / td >
<? php
$ row = $ query-> fetch(PDO :: FETCH_ASSOC);

if (!isset($ nested_List)){
$ nested_List = 1 ;
}
如果(isset($ row)&& is_array($ row)&& $ nested_List ++%3 == 0 ){
echo < / tr> ;< TR GT&;;
}
} while ($ row); // end horizo​​ntal looper
?>
< / table >

解决方案

sql = SELECT * FROM posts WHERE status ='active'ORDER BY id desc LIMIT 6;


query =


db-> prepare(

Below is a code which shows posts from my database in three columns. Initially I am calling 6 posts so if there are 4 or 5 posts in database posts will take there column in table and there is empty space for missing post(works fine). Now I added load more ajax code which is long code so I am not posting here. Now if there are 7 posts in my database, 6 being called initially will be displayed on when I load more posts to call seventh posts it covers whole table instead it should cover space of one column in table with two empty spaces how to do that?

  <?php
$sql = "SELECT * FROM posts WHERE status='active' ORDER BY id desc LIMIT 6";
$query = $db->prepare($sql);
$query->execute();
$row = $query->fetch(PDO::FETCH_ASSOC);
?>


<table cellpadding="5" cellspacing="2">
<tr>
<?php do {
 //horizontal looper
  ?>
          <td'>
<div><h2><a href="blog.php?blogId=<?php echo $row['blogs_id'] ?>"><?php echo $row['title']; ?></a></h2></div>          
          <div><img src='<?php echo $row['pic']; ?>'></div>
          <div><h3><?php echo $row['posted']; ?></h3></div></td>
          <?php
$row = $query->fetch(PDO::FETCH_ASSOC);

if (!isset($nested_List)) {
  $nested_List= 1;
 }
 if (isset($row) && is_array($row) && $nested_List++%3==0) {
   echo "</tr><tr>";
 }
} while ($row); //end horizontal looper 
?>
</table>

解决方案

sql = "SELECT * FROM posts WHERE status='active' ORDER BY id desc LIMIT 6";


query =


db->prepare(


这篇关于使用php显示三列中的帖子。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆