php分页与sql query.only每页需要10个结果

时间:2014-06-25 12:05:52

标签: php sql

我想每页只显示10个项目,现在我在同一页面上显示整个200个项目

<?php
if($dosare_work[0] != "")
{
?>
<ul>
<?php
for($j = 0;$j < count($dosare_work);$j++)
{
$details_work = explode(",",$dosare_work[$j]);

$sql = "SELECT titlu_dosar FROM detalii_dosar WHERE id_dosar = '".$details_work[1]."'";
$result = mysql_query($sql) or die("Query failed with error: ".mysql_error());
$row_titlu = mysql_fetch_array($result);

print '<li style="-webkit-border-radius:0px 0 0 0px;box-shadow:0px 0px 5px #000; 
-moz-border-radius:0px 0 0 0px; background-color:#efefef;margin:0px 0px 5px 0px">
                    <div class="icon doc"></div><a href="/detalii/'.$details_work[1].'"><span style="font-weight:100">'.$row_titlu['titlu_dosar'].'</span><br/>'.$details_work[0].' </a></li>';


}
?>`

1 个答案:

答案 0 :(得分:0)

要获得10个结果,您应该在查询结束时放置LIMIT 10。

完整查询如下所示:

$sql = "SELECT titlu_dosar FROM detalii_dosar WHERE id_dosar = '" .$details_work[1]. "' LIMIT 10"