我希望做一些事情:http://designspiration.net/
他们的页面显示为具有相应数字的文件夹。我假设他们在飞行中这样做,但我不知道如何。不是特别肯定我可能会涉及到什么,或者可能涉及到什么,但我正在接受挑战,所以请告诉我!
以下是我设置的使用$ _GET的当前测试。已经在一些在线教程中获得了一些帮助,以便为分页提供理论。
<?php
$host = "localhost";
$username = "user";
$password = "pass";
$db_name = "database";
$directory = "/newProject";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$postsPerPage = 2;
$start = $_GET['start'];
$totalRecords = mysql_num_rows(mysql_query("SELECT * FROM posts"));
if (!$start)
$start = 0;
$result = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT $start, $postsPerPage");
while ($post = mysql_fetch_assoc($result)){
echo "<span>" ."Title: " .$post['title'] ."</span><br />\n";
echo "<span>" ."Author: " .$post['author'] ."</span><br />\n";
echo "<span>" ."Description: " .$post['description'] ."</span><br />\n";
echo "<a href='full_post.php?id=" .$post['id'] ."'>\n" ."<img src='" .$directory .$post['thumbUrl'] ."' /></a>" ."<br />\n";
echo "<span>" ."Type: " .$post['type'] ."</span><br />\n";
echo "<span>" ."Tags: " .$post['tags'] ."</span><br />\n";
echo "<span>" ."Submitted: " .$post['date'] ."</span><br />\n";
echo "<span>" ."ID: " .$post['id'] ."</span><br /><br /><br />\n";
}
$prev = $start - $postsPerPage;
$next = $start + $postsPerPage;
//previous button
if (!($start<=0))
echo "<a href='index.php?start=$prev'>Prev</a> ";
//page numbers
$pageNumbers = 1;
for($x=0;$x<$totalRecords;$x=$x+$postsPerPage){
if ($start!=$x)
echo "<a href='index.php?start=$x'> $pageNumbers</a> ";
else
echo "<a href='index.php?start=$x'><b> $pageNumbers</b></a> ";
$pageNumbers++;
}
//next button
if(!($start>=$totalRecords-$postsPerPage))
echo "<a href='index.php?start=$next'>Next</a>";
?>
我的假设:我将把我的pagination / mysql_query的变量POST到一个新文件夹和index.php,我根据我的页码动态创建它。我还查看了一个.htaccess重写规则可以修改网址,但我是一个初学者用PHP,试图学习,这似乎是一个捷径。
发布代码,或者只是指向正确的方向!通过搜索没有运气。