0

您好,此代码用于在用户个人资料中写帖子代码正确且没有任何错误,但是在写帖子时我有错误新帖子将是最后一个帖子我的意思是我在排序时出错了如何修复以制作新帖子它的第一篇文章,如 facebook 或任何社交网络

<?php
if (isset ($_SESSION['user_login']))
{
    $user = $_SESSION["user_login"];`enter code here`
}
else
{
$user = "";
}
    $date_added = date ("Y-m-d");
    $added_by =$user;
    $user_posted_to = '';   


$post = @$_POST['post'];

if ($post != '')
   {
    $date_added = date ("Y-m-d");
    $added_by = $user;
    $user_posted_to = $user;
    $sqlCommand = "INSERT INTO posts (id,body,date_added,added_by,user_posted_to) VALUES ('','$post','$date_added','$added_by','$user_posted_to')";
    $query = mysql_query ($sqlCommand) or die (mysql_error());

    $getposts = mysql_query("SELECT * FROM posts WHERE user_posted_to ='$user' ") or die(mysql_error());
    while ($row = mysql_fetch_assoc($getposts)) 
                    {
                    $id = $row['id'];
                    $body = $row['body'];   
                    $date_added = $row['date_added'];
                    $added_by = $row['added_by'];
                    $user_posted_to = $row['user_posted_to'];  

                 echo "

                    <div class='posted_by'>
                    Posted by:
                                            <a href='$added_by'>$added_by</a> on $date_added</div>
                                            <br />
                                            <div  style='max-width: 600px;'>
                                            $body<br /><p />
                                            </div></br>
                                            <hr />
                    ";
                    }
   }
else
{

    $getposts = mysql_query("SELECT * FROM posts WHERE user_posted_to ='$user' ") or die(mysql_error());
    while ($row = mysql_fetch_assoc($getposts)) 
                    {
                    $id = $row['id'];
                    $body = $row['body'];   
                    $date_added = $row['date_added'];
                    $added_by = $row['added_by'];
                    $user_posted_to = $row['user_posted_to'];  

                 echo "

                    <div class='posted_by'>
                    Posted by:
                                            <a href='$added_by'>$added_by</a> on $date_added</div>
                                            <br />
                                            <div  style='max-width: 600px;'>
                                            $body<br /><p />
                                            </div></br>
                                            <hr />
                    ";
                    }
}



?>
4

1 回答 1

0
$getposts = mysql_query("
    SELECT * 
    FROM posts 
    WHERE user_posted_to ='$user'
    order by id desc
") or die(mysql_error());
于 2013-03-20T18:35:39.943 回答