添加帖子会更改上一个的值而不是添加新值

时间:2017-05-10 20:34:08

标签: php

我正在写一个我要添加帖子的页面,但在我添加帖子的标题和内容并转到主页面调用添加帖子的php函数后,之前添加的帖子只是更改了标题和新内容的内容。

PHP代码:

<?php
function drawPost(){
        $id=$_COOKIE['id'];
        $connect = new mysqli('localhost', 'root', '', 'data');
        $title=$connect->query("SELECT `title` FROM `posts` WHERE `id`='$id'")->fetch_object()->title;
        $content=$connect->query("SELECT `content` FROM posts WHERE `id`='$id'")->fetch_object()->content;
        $img=$connect->query("SELECT `img` FROM posts WHERE `id`='$id'")->fetch_object()->img;
            $result2 = '<div class="center">';
            $result2 .= '<h1><a class="titles" href="post.php">';
            $result2 .= $title;
            $result2 .= '</a></h1>';
            $result2 .= '<h2 class="date">';
            $result2 .=  date ('F, jS Y');
            $result2 .= '</h2>';
            $result2 .= '<img src="stories.jpg" alt="" class="thumb">';
            $result2 .= '<h2 class="content">';
            $result2 .= $content;
            $result2 .= '</h2>';
            $result2 .= '</div>';
            return $result2;
}
?>

在主页面上,我只需要调用此功能:

<?php
  echo drawPost();
?>

修改 添加内容的第一篇文章看起来像我所包含的图片的左侧,然后当我添加第二篇文章时,我希望第一篇文章向下移动一点并为第二篇文章创建一个位置。但是,当我添加第二篇文章时,php只会改变第一篇文章的值。

删除了图片,我无法添加第三张图片,因为我是新来的,并且没有足够的声誉。

编辑2: 显示上一篇文章和新帖子。它只是替换值并保持在同一个地方。 哦,下面的帖子称为'第二篇文章的标题'刚刚添加到html中(一旦我弄清楚或得到这个问题的答案,它将在php中完成),php没有成功。 Previous post

New Post

0 个答案:

没有答案
相关问题