Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 限制从sql数据库中提取的行数并将其组织到页面中_Php_Mysql_Sql - Fatal编程技术网

Php 限制从sql数据库中提取的行数并将其组织到页面中

Php 限制从sql数据库中提取的行数并将其组织到页面中,php,mysql,sql,Php,Mysql,Sql,目前,我有一个页面列出了我的员工提交的费用。问题是它会从提交的费用表中提取Everyyyyy行。。。因此,加载页面需要花费很长时间(我们有2006年的数据!!!)我会清理表格,但由于我们的政策,我们需要保持10年的记录 在任何情况下,我希望这个页面列出25个条目,并希望有这样的页面选项,每个页面将显示25个条目。与讨论相关的PHP代码是: <?php $forms = array(); if ($checkr[4]==2) $dtfq = mysql_query("SELECT `

目前,我有一个页面列出了我的员工提交的费用。问题是它会从提交的费用表中提取Everyyyyy行。。。因此,加载页面需要花费很长时间(我们有2006年的数据!!!)我会清理表格,但由于我们的政策,我们需要保持10年的记录

在任何情况下,我希望这个页面列出25个条目,并希望有这样的页面选项,每个页面将显示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++) {
?>

我发现此资源很有用,但不能满足我的需要:

谢谢


TK

你在谈论分页。这样做:

<?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>&nbsp;'.$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。您还可能需要考虑在系统中具有筛选/搜索功能。或者按年份对它们进行分类。

看看这个页码正是医生所要求的。另请看=>该页面上有一些您可能感兴趣的演示。请考虑切换到<代码> MySqLI**<代码>或PDO;