- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前,我有一个页面列出了我的员工提交的费用。问题是它从提交的费用表中提取每一行...因此加载页面需要很长时间(我们的数据可以追溯到 2006 年!!!)我会清除该表,但由于我们的政策,我们需要保持10年的记录..
无论如何,我希望此页面列出 25 个条目,并且希望可以选择具有像 <<1|2|3|4|5>> 这样的页面,其中每个页面将显示 25 个条目。与讨论相关的 PHP 代码是:
<?php
$forms = array();
if ($checkr[4]==2)
$dtfq = mysql_query("SELECT `index`,`time`,`status`,`user` FROM `dtf` ORDER BY `index` desc;");
else
$dtfq = mysql_query("SELECT `index`,`time`,`status`,`user` FROM `dtf` WHERE `user`=".$checkr[0]." ORDER BY `index` desc;");
while($dtf = mysql_fetch_row($dtfq)) {
$newentry = array(1,$dtf[0],$dtf[1],$dtf[2],$dtf[3]);
$forms[] = $newentry;
}
if ($checkr[4]==2)
$crfq = mysql_query("SELECT `index`,`time`,`status`,`user` FROM `crf` ORDER BY `index` desc;");
else
$crfq = mysql_query("SELECT `index`,`time`,`status`,`user` FROM `crf` WHERE `user`=".$checkr[0]." ORDER BY `index` desc;");
while ($crf = mysql_fetch_row($crfq)) {
$newentry = array(2,$crf[0],$crf[1],$crf[2],$crf[3]);
$forms[] = $newentry;
}
for ($i=0; $i<count($forms); $i++) {
for ($j=0; $j<count($forms); $j++) {
if ($forms[$j][2]<$forms[$i][2]) {
$temp = $forms[$j];
$forms[$j] = $forms[$i];
$forms[$i] = $temp;
}
}
}
for ($i=0; $i<count($forms); $i++) {
?>
我发现此资源很有帮助,但不能满足我的需求:Need to pull last x number of rows based on date
谢谢
传统知识
最佳答案
您谈论的是分页。这样做:
<?php
include 'conn.php'; /* Assume that this has your connection to your DB and put your connection to $con variable */
$dtfq = "SELECT `index`,`time`,`status`,`user` FROM `dtf` ORDER BY `index` DESC";
$result = mysqli_query($con, $dtfq); /* Do the Query */
$count=mysqli_num_rows($result); /* Count the number of rows */
$r = mysqli_fetch_row($result);
$numrows = $r[0];
echo '<b> '.$count.' results found</b>';
$rowsperpage = 25; /* Your request to have 25 entries per page */
$totalpages = ceil($count / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$dtfq = "SELECT `index`,`time`,`status`,`user` FROM `dtf` ORDER BY `index` DESC LIMIT $offset, $rowsperpage";
$result=mysqli_query($con, $dtfq);
/*start of the table*/
echo "<table border='1'>
<tr>
<th>Index</th>
<th>Time</th>
<th>Status</th>
<th>User</th>
</tr>";
/*start of the record display*/
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['index'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['user'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo '<table border="0"><tr><td>';
/****** build the pagination links ******/
$range = 2;
if ($currentpage > 1) {
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " <font color='#546f3e'><b>$x</b></font> ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a> ";
} // end if
/****** end build pagination links ******/
echo '</td></tr></table>';
?>
并且请使用 mysqli 而不是它的前身 mysql。您可能还需要考虑在系统中添加过滤/搜索功能。或者按年份对它们进行分类。
关于php - 限制从 SQL 数据库中提取的行数并组织成页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22240904/
我有一个包含未定义条目数的数据文件,如下所示: A B C D E.. 1 0 2 5 4 7 4 3 4 1 8 7 4 0 7 1 1 第一行代表工作时间,而不是暂停等交替方式。为了可
我需要有关小型 SQL 查询的帮助。考虑下表: TicketNo | Rules | Audit Result --------------------------------- P
我有一个非常大的表(~1 000 000 行)和带有联合、连接和 where 语句的复杂查询(用户可以选择不同的 ORDER BY 列和方向)。我需要获取分页的行数。如果我运行查询而不计算行数,它会很
我想获取数据帧的行数。 我可以通过 size(myDataFrame)[1] 实现这一点. 有更干净的方法吗? 最佳答案 如果您正在使用 DataFrames具体来说,那么你可以使用 nrow() :
是否可以在带有千位分隔符的 VIM 状态栏中显示行数,最好是自定义千位分隔符? 例子: set statusline=%L 应该导致“1,234,567”而不是“1234567”。 最佳答案 我找到了
我有一个非常基本的问题,但不知道该怎么做。如果 mysql 表中的行数增加,我想刷新页面。我已经尝试了一些不同的事情,比如在表中添加一个单独的列,如果行数和这个值相等,则值为 (id + 1),然后进
我的 mysql TB 中的行数(如 TB 信息中所示)是 11093,而自动递增 ID(从 1 开始)是 11361。为什么会这样? 最佳答案 删除的行不会重置 AI 索引。行数是当前表中的条目数,
我有一个 MySQL 表如下。 emp_no emp_name dob gender 1 A 1978-10-10 Male 2 B
ifstream inFile; inFile.open(filename); //open the input file stringstream strStream; strStream << i
SELECT * FROM table1 WHERE EXISTS (SELECT * FROM table2 WHERE *condition*) 例如,我可以检查是否有 3 行符合 table2
我正在尝试提取 SQL 表中的总行数。 我正在使用以下代码: $rowNum = mysql_query("SELECT COUNT(*) FROM Logs"); $count = mysql_fe
我想知道表格 View 的行宽是多少,UITableViewCell 文本标签的字体是什么,有人可以帮我吗? 最佳答案 NSLog(@"width: %f", cell.frame.size.widt
对于以下内容: def linecount(filename): count = 0 for x in open(filename): count += 1 r
感谢关注。 我用C语言写了一段代码来统计字数、行数和字符数。 while((c = fgetc(fp)) != EOF) { if((char)(c) == ' ' || (char)(c)
我是 matlab 的新手,只需要更改代码中的一个非常小的东西。我有以下矩阵: ans = 1 1 1 1 2 1 2 1
我只是想弄清楚如何确定行数,然后使该数字显示在 HTML 中。 我准备好的声明如下所示: if($stmt = $mysqli -> prepare("SELECT field1, field2, f
PDO 显然无法计算从选择查询返回的行数(mysqli 有 num_rows 变量)。 除了使用 count($results->fetchAll()) 之外,有没有办法做到这一点? 最佳答案 根据手
SELECT count(*) FROM Stack WHERE Id = 33478 GROUP BY SID Output: (No column name) 1 4 对于结果;有两排。怎么退货
IE。如果我们有一个包含400万行的表。 其中具有一个STATUS字段,该字段可以采用以下值:TO_WORK,BLOCKED或WORKED_CORRECTLY。 您是否会在一个仅会更改一次的字段上进行
所以在JTextArea中有一个getLineCount()是否有与JTextPane类似的东西,因为我可以找到任何东西。也许有不同的方法来获得它?我想获取当前存在的行数。 最佳答案 (正如您所指出的
我是一名优秀的程序员,十分优秀!