添加分页到我的mysql查询

时间:2012-06-03 14:05:19

标签: php mysql pagination while-loop

  

可能重复:
  PHP & MySQL Pagination

我对如何在我的mysql查询中添加分页感到有点困惑,因为我循环遍历结果并且每次都将它们添加到变量中:

$DBQuery3 = mysqli_query($dblink, "SELECT * FROM images WHERE project_id = '$FormProjectID'");

$ProjectContent ='';
                        while($row = mysqli_fetch_array($DBQuery3)) {
                            $DBImageID = $row['image_id'];
                            $DBProjectID = $row['project_id'];
                            $DBImageName = $row['image_name'];
                            $DBImageDescription = $row['image_description'];
                            $DBDateCreated = $row['date_created'];
                            $DBLinkToFile = $row['link_to_file'];
                            $DBLinkToThumb = $row['link_to_thumbnail'];
                            $DBGivenName = $row['given_name'];

                            //if the image was given a name by the user, display it
                            //otherwise display the generated name

                            if (strlen($DBGivenName) > 1) {
                                $FileName = $DBGivenName;
                            } else {
                                $FileName = $DBImageName;
                            }

                            $ProjectContent .= '
                                <a href="index.php?page=image&id='.$DBImageID.'"><img src="uploads/'.$DBLinkToThumb.'" width="150px" height="150px" alt="'.$FileName.'" title="'.$FileName.'"/></a>
                            ';

任何指向正确方向的人都会非常感激。

1 个答案:

答案 0 :(得分:0)

HY,

尝试使用php分页脚本,网上有很多,只搜索那些单词。

例如:http://www.coursesweb.net/php-mysql/pagination-class-script_s2可以将存储在数据库或数组中的数据分页。