要在选择选项n php分页后每页显示不同的行?

要在选择选项n php分页后每页显示不同的行?,php,html,mysql,pagination,Php,Html,Mysql,Pagination,上面的代码显示分页中的sql记录每页仅显示30行,因为$recordPerPage='30';。我想在html中创建一个selectbox,其中包含30到100行的选项,并将其传递给$recordPerPage,这样当我选择任何选项时,它将根据所选选项显示每页的行数。提前感谢您的帮助。您必须进行更改 $start_date = $_REQUEST['date1']; $end_date = $_REQUEST['date2']; $condition="1=1"; if($start_date!

上面的代码显示分页中的sql记录每页仅显示30行,因为$recordPerPage='30';。我想在html中创建一个selectbox,其中包含30到100行的选项,并将其传递给$recordPerPage,这样当我选择任何选项时,它将根据所选选项显示每页的行数。提前感谢您的帮助。

您必须进行更改

$start_date = $_REQUEST['date1'];
$end_date = $_REQUEST['date2'];
$condition="1=1";
if($start_date!="")
$condition.=" AND event_date>='".date( "Y-m-d", strtotime($start_date))."'";
if($end_date!="")
$condition.=" AND event_date<='".date( "Y-m-d", strtotime($end_date))."'";
$start_date = date( "Y-m-d", strtotime($start_date)); 
$end_date = date( "Y-m-d", strtotime($end_date));
$link = mysql_connect('localhost', 'username', 'password');

if (!$link) 
 {
die('Could not connect: ' . mysql_error());
}
if($_REQUEST["dir"]=="" || $_REQUEST["dir"]=="desc")
$dir="asc";
else
    $dir="desc";

  if($_REQUEST["orderby"]!="")$ord = " ORDER BY ".$_REQUEST["orderby"];
  if($_REQUEST["dir"]!="")$ord .= " ".$_REQUEST["dir"];

 mysql_select_db("intern_db", $link);


$page = (intval($_GET['page'])>0) ? $_GET['page'] : 1;
$recordPerPage= '30';
$startPoint = ($page - 1)*$recordPerPage;
$result = mysql_query("SELECT count(*) cnt FROM ` admin_crmf_poc_event_history` where $condition");
        $row = mysql_fetch_array($result);
        $num_rows = $row["cnt"];

$result = mysql_query("SELECT * FROM ` admin_crmf_poc_event_history` where $condition $ord LIMIT $startPoint,$recordPerPage");
        $totalPages=ceil($num_rows/$recordPerPage);

if(!$totalPages){
   echo "There is no record.";
}
else{
   echo "$recordPerPage records are shown.";

   }
 echo "<table  width='100%'>

   <tr>
     <th><code><a href= 'index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"].          "&orderby=id&dir=".$dir."'>Id</code></th>
     <th><a href= 'index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=event_date&dir=".$dir."'>Event Date</a></th>
     <th><a href= 'index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=bdm_name&dir=".$dir."'>BDM Name</th>
     <th><a href= 'index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=event_type&dir=".$dir."'>Event Performed</th>
     <th><a href= 'index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=completed&dir=".$dir."'>Completed</th>
   </tr>";

while($row = mysql_fetch_array($result))
    {
      echo "<tr>";
      echo "<td>" . $row['id'] . "</td>";
      echo "<td>" . date( "m/d/Y", strtotime($row['event_date'])) . "</td>";
      echo "<td>" . $row['bdm_name'] . "</td>";
      echo "<td>" . $row['event_type'] . "</td>";
      echo "<td>" . $row['completed'] . "</td>";
      echo "</tr>";
    }
 echo "</table>";
mysql_close($link);


并在选择框中使用该名称。

您的代码中已经有了答案,只需执行所做的操作即可获得$page变量。如果有问题,您也可以考虑将页码重置为1。我的意思是,若用户在第2页,将记录值从30更改为100,将第2页重置为1可能是个好主意


$recordPerPage=intval$\u获取['records']>0$_获取['records']:1

嗯…你在哪里?有错误/警告吗?没有,我只想创建一个选择框。我知道如何创建它,但我不知道如何在“选择”选项中获取每页的行数使用分页搜索将节省大量时间!!:D
$recordPerPage= '30';
$recordPerPage= $_REQUEST ['recordPerPage'];