0

有人可以建议如何解决这个问题吗?

我想从我的 SHOUTBOX 表中按 id 调用前 50 行,但按升序将它们显示在 div 中(最近的行(最新的)在底部)

例如;

最近的行是 id 200,我想调用第 150 - 200 行,将它们显示在 div 中;

150, 151, 152, . . 。ETC 。. 200 <<< DIV 中的最后一行

我的 PHP 代码目前看起来像这样;

$recall=mysql_query("SELECT *, DATE_FORMAT(timepost,'%H:%i:%s') as timepost FROM shoutbox ORDER BY id DESC LIMIT 50");

    while($comm=mysql_fetch_object($recall)){
      if ($comm->poster == "System"){
      print"<font color=#3399FF>$comm->timepost-<strong><a href='profile.php?viewuser=$comm->poster' target='iframecontent'><font color=#3399FF>$comm->poster</font></a></strong>: </font>";
    echo replace($comm->post);
    echo"<br>";
      }

但它会在 div 中返回我的数据,例如;

200、199、198、. . 。ETC 。. 150 <<< DIV 中的最后一行

请问有人可以帮忙吗?

注意:我目前正在浏览我的所有页面并将所有 mySQL 查询转换为 PDO

4

5 回答 5

1

替换ORDER BY id DESCORDER BY id

于 2013-03-30T15:30:38.510 回答
1

For future reference, if you're converting to PDO there is the exact answer for reading backwards on this page without changing your query. http://www.php.net/manual/en/pdostatement.fetch.php.

For now this will work:

SELECT *, DATE_FORMAT(timepost,'%H:%i:%s') AS timepost FROM (SELECT * FROM shoutbox ORDER BY id DESC LIMIT 50) AS foo ORDER BY id ASC
于 2013-03-30T15:32:14.673 回答
1

Ok, try this:

$recall=mysql_query("SELECT *, DATE_FORMAT(timepost,'%H:%i:%s') as timepost FROM (SELECT * FROM shoutbox ORDER BY id DESC LIMIT 50) ORDER BY id ASC");
于 2013-03-30T15:36:43.483 回答
0

You have wrong the order command, you have to put ASC instead of DESC Here is your correct query:

$recall=mysql_query("SELECT *, DATE_FORMAT(timepost,'%H:%i:%s') as timepost FROM shoutbox ORDER BY id ASC LIMIT 50");

    while($comm=mysql_fetch_object($recall)){
      if ($comm->poster == "System"){
      print"<font color=#3399FF>$comm->timepost-<strong><a href='profile.php?viewuser=$comm->poster' target='iframecontent'><font color=#3399FF>$comm->poster</font></a></strong>: </font>";
    echo replace($comm->post);
    echo"<br>";
      }
于 2013-03-30T15:30:59.967 回答
0

Change your query to:

$recall = mysql_query("SELECT *, DATE_FORMAT(timepost,'%H:%i:%s') as timepost 
   FROM shoutbox ORDER BY id ASC LIMIT 50");
于 2013-03-30T15:31:21.507 回答