如果我已经将票证表设置为拆分为多个页面,如何使其底部具有页面链接?
这个问题已得到解答。 单击此处查看回答我问题的答案。
编辑:
我仍然不知道该怎么做。有人可以帮忙吗?我知道它被称为“分页”,但我不知道如何让它在底部显示页面链接。我希望有人能够提供帮助。
I have a table of tickets and all of the data is loaded in from a database to the table. I have pages on it (using
?page=1
, ?page=2
, etc.) but, how can I make it where it has "Next Page", "Previous Page", "Last Page", "Page something of something", etc. at the bottom?完成这一切的代码是:
<table id="tickets">
<tr>
<th>Name</th>
<th>Email</th>
<th>Subject</th>
<th>Created on</th>
<th style="width:65px;">Status</th>
<th>Actions</th>
</tr><?php
$startpoint = $_GET["page"];
if (isset($_GET["page"])) {
$startpoint = $_GET["page"];
}
else {
$startpoint = 1;
}
$startpoint = $startpoint - 1;
$startpoint = $startpoint * 10;
$endpoint = $startpoint + 10;
function addEllipsis($string, $length) {
$end = "...";
if (strlen($string) > $length) {
$length -= strlen($end); // $length = $length – strlen($end);
$string = substr($string, 0, $length);
$string .= $end; // $string = $string . $end;
}
return $string;
}
$x = 1;
if ($show == "active") {
$result = mysql_query("SELECT * FROM tickets WHERE is_active='1'");
while ($info = mysql_fetch_array($result)) {
$x++;
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
if ($isActive == '1') {
$status = "<span class=\"open\">Open</span>";
}
if ($isActive == '0') {
$status = "<span class=\"closed\">Closed</span>";
}
if ($x > $startpoint && $x < $endpoint) {
echo "
<tr>
<td>".$name."</td>
<td>".$email."</td>
<td title=\"".$subject."\">".addEllipsis($subject, 16)."</td>
<td>".$created."</td>
<td>".$status."</td>
<td><a href=\"/employee/employee.php?ticket=".$ticketid."\">View ticket »</a></td>
</tr>";
}
}
}
else if ($show == "closed") {
$result = mysql_query("SELECT * FROM tickets WHERE is_active='0'");
while ($info = mysql_fetch_array($result)) {
$x++;
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
if ($isActive == '1') {
$status = "<span class=\"open\">Open</span>";
}
if ($isActive == '0') {
$status = "<span class=\"closed\">Closed</span>";
}
if ($x > $startpoint && $x < $endpoint) {
echo "
<tr>
<td>".$name."</td>
<td>".$email."</td>
<td title=\"".$subject."\">".addEllipsis($subject, 16)."</td>
<td>".$created."</td>
<td>".$status."</td>
<td><a href=\"/employee/employee.php?ticket=".$ticketid."\">View ticket »</a></td>
</tr>";
}
}
}
else {
$result = mysql_query("SELECT * FROM tickets");
while ($info = mysql_fetch_array($result)) {
$x++;
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
if ($isActive == '1') {
$status = "<span class=\"open\">Open</span>";
}
if ($isActive == '0') {
$status = "<span class=\"closed\">Closed</span>";
}
if ($x > $startpoint && $x < $endpoint) {
echo "
<tr>
<td>".$name."</td>
<td>".$email."</td>
<td title=\"".$subject."\">".addEllipsis($subject, 16)."</td>
<td>".$created."</td>
<td>".$status."</td>
<td><a href=\"/employee/employee.php?ticket=".$ticketid."\">View ticket »</a></td>
</tr>";
}
}
}
?>
</table>
我怎样才能让它在底部显示每个页面的链接(只是一个简单的“1”、“2”等)?我无法自己创建它们,因为我不知道有多少页面之类的东西。如果当您位于某个页面时链接可以变成灰色的不可点击文本,那就太好了。有人帮助我使用页面功能,但他们不在线,所以他们无法帮助我。 (我还不太擅长 PHP)有人知道如何实现这一点吗?
This question is answered. Click here to see the answer that answered my question.
Edit:
I still don't know exactly how to do this. Could someone help? I get the fact that it's called "pagination" but I don't know how to make it display page links at the bottom. I hope someone will be able to help.
I have a table of tickets and all of the data is loaded in from a database to the table. I have pages on it (using
?page=1
, ?page=2
, etc.) but, how can I make it where it has "Next Page", "Previous Page", "Last Page", "Page something of something", etc. at the bottom?The code that does it all is:
<table id="tickets">
<tr>
<th>Name</th>
<th>Email</th>
<th>Subject</th>
<th>Created on</th>
<th style="width:65px;">Status</th>
<th>Actions</th>
</tr><?php
$startpoint = $_GET["page"];
if (isset($_GET["page"])) {
$startpoint = $_GET["page"];
}
else {
$startpoint = 1;
}
$startpoint = $startpoint - 1;
$startpoint = $startpoint * 10;
$endpoint = $startpoint + 10;
function addEllipsis($string, $length) {
$end = "...";
if (strlen($string) > $length) {
$length -= strlen($end); // $length = $length – strlen($end);
$string = substr($string, 0, $length);
$string .= $end; // $string = $string . $end;
}
return $string;
}
$x = 1;
if ($show == "active") {
$result = mysql_query("SELECT * FROM tickets WHERE is_active='1'");
while ($info = mysql_fetch_array($result)) {
$x++;
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
if ($isActive == '1') {
$status = "<span class=\"open\">Open</span>";
}
if ($isActive == '0') {
$status = "<span class=\"closed\">Closed</span>";
}
if ($x > $startpoint && $x < $endpoint) {
echo "
<tr>
<td>".$name."</td>
<td>".$email."</td>
<td title=\"".$subject."\">".addEllipsis($subject, 16)."</td>
<td>".$created."</td>
<td>".$status."</td>
<td><a href=\"/employee/employee.php?ticket=".$ticketid."\">View ticket »</a></td>
</tr>";
}
}
}
else if ($show == "closed") {
$result = mysql_query("SELECT * FROM tickets WHERE is_active='0'");
while ($info = mysql_fetch_array($result)) {
$x++;
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
if ($isActive == '1') {
$status = "<span class=\"open\">Open</span>";
}
if ($isActive == '0') {
$status = "<span class=\"closed\">Closed</span>";
}
if ($x > $startpoint && $x < $endpoint) {
echo "
<tr>
<td>".$name."</td>
<td>".$email."</td>
<td title=\"".$subject."\">".addEllipsis($subject, 16)."</td>
<td>".$created."</td>
<td>".$status."</td>
<td><a href=\"/employee/employee.php?ticket=".$ticketid."\">View ticket »</a></td>
</tr>";
}
}
}
else {
$result = mysql_query("SELECT * FROM tickets");
while ($info = mysql_fetch_array($result)) {
$x++;
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
if ($isActive == '1') {
$status = "<span class=\"open\">Open</span>";
}
if ($isActive == '0') {
$status = "<span class=\"closed\">Closed</span>";
}
if ($x > $startpoint && $x < $endpoint) {
echo "
<tr>
<td>".$name."</td>
<td>".$email."</td>
<td title=\"".$subject."\">".addEllipsis($subject, 16)."</td>
<td>".$created."</td>
<td>".$status."</td>
<td><a href=\"/employee/employee.php?ticket=".$ticketid."\">View ticket »</a></td>
</tr>";
}
}
}
?>
</table>
How could I make it show links to the each page (just a simple "1", "2", etc.) at the bottom? I can't create them myself because I wont know how much pages there is and stuff. It would also be great if the link could turn into grey non-clickable text when you are on that certain page. Someone helped me with the page feature but they aren't online right so they can't help me. (I'm not that good at PHP yet) Anyone know how to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-编辑-
聊天后,解决方案包括向查询添加
LIMIT
而不是使用$x
来防止显示某些行,如下所示:https://gist.github.com/1233850运行以下代码,因为它可以单独工作,所以可能会给您一个想法:
-edit-
After chat, the solution that includes adding a
LIMIT
to the query instead of using$x
to prevent showing certain rows was the following: https://gist.github.com/1233850Run the following code, since it works on its own it may give you an idea:
好的,一般可以这样完成:
Good start。要获取页数,您需要计算每页 db/items 中的记录数。
好的,生成菜单的页码(假设我们想要像“< 1 ... 3 4 5 ...最后>”->其中$curretnPage = 4):
...它变得有点复杂,也许有更好、更快的方法,但你可以看到它是如何完成的(不知道它“应该如何完成”)。它并不完整,但是......你知道该怎么做:)
我希望你的意思是,你不能创建菜单...如果你有带有数字的数组,只需循环并创建带有数字的html链接,然后将“...”插入0。
干杯
Ok, generally it may be done like this:
Good start. To get the number of pages you need to count records in db/items per page.
Ok, generate the page numbers for menu(lets say we want sth like "< 1 ... 3 4 5... last >" -> where $curretnPage = 4):
... it's getting kind of complicated, maybe there is a better, faster way, but you can see how it can be done(dunno exactly how it "should be done"). It's not complete, but... you know what to do:)
I hope that what you meant, that you can't create menu... If you have array with numbers just loop and create html links with numbers and put "..." insted of 0.
Cheers