如何只选择前5个结果,然后显示更多..选项?

时间:2011-03-16 22:20:55

标签: php mysql search

如何选择前5个结果,然后添加更多选项?

以下是当前代码:

  <?php

   $query="SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC";
   $result=mysql_query($query);

   $num=mysql_numrows($result);

    mysql_close();

    echo "";

     $i=0;
     while ($i < $num) {

  $otheris=mysql_result($result,$i,"sender_full_name"); 
  $sysid=mysql_result($result,$i,"sender_id");
   $dob=mysql_result($result,$i,"dob");

    // If $dob is empty
   if (empty($dob)) {

   $dob = "No new messages - 
   <a  id=missingdob href=/test.php?id=$uid>
   <bold>check later</bold></a>";
   }

   echo "<br><div id=linkcontain>
   <a id=otherlink href=$mem/profile.php?id=$uid>
    $manitis</a>
         <br><div id=dobpres>$dob</div></div>";

   echo "";

    $i++;
      }

       ?>

3 个答案:

答案 0 :(得分:2)

你应该尝试第一次选择6行,如果你得到6个记录,那么先显示5个“显示更多选项”

"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 0, 6";

以后您应该像这样查询:

"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 6, 5";
"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 11, 5";
"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 16, 5";
...
...

如果您能够获取请求的记录数,则每次“显示更多选项”。

答案 1 :(得分:1)

$query="SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 5"; 

http://dev.mysql.com/doc/refman/5.5/en/select.html

你可以考虑LIMIT 6只显示最多5个,如果存在第6个显示有更多选项......

答案 2 :(得分:1)

{
    "event": {
        "header": {
            "namespace": "Alexa.Discovery",
            "name": "Discover.Response",
            "payloadVersion": "3",
            "messageId": "asdf"
        },
        "payload": {
            "endpoints": [
                {
                    "endpointId": "asdf",
                    "capabilities": [
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa.Cooking",
                            "version": "3",
                            "properties": {
                                "supported": [
                                    {
                                        "name": "cookingMode"
                                    }
                                ],
                                "proactivelyReported": true,
                                "retrievable": true,
                                "nonControllable": false
                            },
                            "configuration": {
                                "supportsRemoteStart": true,
                                "supportedCookingModes": [
                                    {
                                        "value": "OFF"
                                    },
                                    {
                                        "value": "BAKE"
                                    },
                                    {
                                        "value": "CUSTOM",
                                        "customName": "FANCY_NANCY_MODE"
                                    }
                                ]
                            }
                        }
                    ]
                }
            ]
        }
    }
}