【问题标题】:how to post data by ID desc如何按 ID desc 发布数据
【发布时间】:2012-11-03 06:12:30
【问题描述】:
$query="select * from messages where client_id='$client_id' ORDER BY `id` DESC";

上面的脚本似乎不起作用,我想选择所有等于用户输入的数据,同时按降序发布

  $result = $mysqli->query( $query );

                                        while ($row = $result->fetch_object())
                                        {
                                                $mes_agent_id = $row->poster_id;
                                                $id = $row->msg_id;
                                                $mes = $row->message;
                                                $mes = nl2br($mes);
                                                $cdate = $row->date_post;
                                                $msg ="{$mes} <br> . {$cdate}";

                                                $query_agnt ="select * from agent_info where id='$mes_agent_id'";
                                                $result_agnt = $mysqli->query( $query_agnt );
                                                $row_agnt = $result_agnt->fetch_object();
                                                        $mes_agent_first = $row_agnt->first;
                                                        $mes_agent_last = $row_agnt->last;
//wall ===================================================
?>
<li class="bar<?php echo $id; ?>">
<div id="news-avatar">
<img src="data/agentpic/<?php echo $mes_agent_first.$mes_agent_last; ?>.jpg" style="height:50px;float:left;margin-right:10px;"/>
</div>
<div align="left" class="post_box">
<br><label><strong><?php echo $mes_agent_first.' '.$mes_agent_last; ?></strong></label> <br> <br>
<?php echo $msg; ?> 

<br><br><a href="#" class="comment" id="4">comment</a><br>
</div>
<div id='expand_box'>
<div id='expand_url'></div>
</div>
<div id="fullbox" class="fullbox<?php echo $id; ?>">
<div id="commentload<?php echo $id; ?>" >

如何从数据库中按降序发布数据,同时选择应该选择数据的位置?

【问题讨论】:

    标签: php database mysqli output


    【解决方案1】:

    请更改此声明:

    $query="select * from messages where client_id='" . $client_id ."' ORDER BYidDESC";

    【讨论】:

      【解决方案2】:

      您必须在 column_name 和 table_name 的开头和结尾使用“`”,或者只使用 column_name 和 table_name 但不要同时使用两者。

      你这样使用:

      "select * from `messages` where `client_id`='$client_id' ORDER BY `id` desc";
      

      或者你可以使用

      "select * from messages where client_id='$client_id' ORDER BY id desc";
      

      最好在php中使用addslashes()函数和$client_id来防止sql注入。

      像这样:

      $client_id = addslashes($client_id);
      "select * from messages where client_id='$client_id' ORDER BY id desc"
      

      我希望它会为你完成。

      【讨论】:

        猜你喜欢
        • 2014-02-17
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多