使用表单中的不同条件显示带分页的记录

时间:2017-10-03 22:03:17

标签: php mysql forms pagination

我一直在寻找这个很长一段时间,但一直没能得到任何东西。我有一个下拉列表,显示名称,开始和结束日期。我想使用名称,开始和结束日期对数据进行分页,这意味着如果您选择名称(ABC),那么该名称的所有X记录应该每页Y记录分页。我的分页工作,但我怎么能让它在这些标准内工作?如果我转到另一个页面,那么它只会返回显示所有数据,但它仍然是每页Y.

    if(isset($_GET['submit']) || isset($_GET['page'])){ 
    echo '<center>';
    echo '<br>';
    $sql = "SELECT SFID, Comment, Time 
            FROM tbl_call_log_detail 
            WHERE
            ( dealer_id = '$call_id' AND 
              '$endDate'='1970-01-01' AND 
              '$startDate' ='1970-01-01'
            )
            OR 
            ( Time <= '$endDate' AND 
              Time >= '$startDate' AND 
              ( dealer_id = '$call_id' OR '$call_id'='' )
            )    
            OR 
            ( '$endDate'='1970-01-01' AND 
              '$startDate' ='1970-01-01' AND 
              '$call_id'=''
            )
            ORDER BY Time DESC 
            LIMIT $start_from, $record_per_page ";

我认为我的选择查询在某个地方有问题,但如果需要,我也可以提出我的代码的其他部分。这是我最后一次问到的,但我仍然被卡住了:Can we display table records in multiple pages using POST?

修改

这就是我分配帖子和获取变量的方式:

$edate = '';
$sdate = '';
$urlparameter = '';
$call_id = '';
if(isset($_GET['account_name'])){
    $account_name = $_GET['account_name'];
    $urlparameter = "&account_name=".$account_name;
}
if(isset($_GET['edate'])){
    $edate = $_GET['edate'];
    $urlparameter .= "&edate=".$edate;
}
if(isset($_GET['sdate'])){
    $sdate = $_GET['sdate'];
    $urlparameter .= "&sdate=".$sdate;
}
 $endDate = date('Y-m-d', strtotime($edate));
 $startDate = date('Y-m-d', strtotime($sdate));

// Displaying the relevant data on the page
$record_per_page = 5;
 $page = '';
 if(isset($_GET['page'])){
     $page = intval($_GET['page']);
 }
 else{
     $page = 1;
 }
 $start_from = ($page - 1) * $record_per_page;...

HTML表格

<form action = "" name = "dealer_call_log" id = "myform" method = "get">
<input type = "submit" name = "logout" id = "logout" value = "Log Out" />
Name of the dealer:<br>
<?php
//Displaying the names of all the dealers in the database 

$sql = "SELECT * FROM tbl_dealer_info ";
$sql .= "ORDER BY account_name ASC ";
$result = mysqli_query($conn, $sql);
echo "<select name = 'account_name' id = 'idaname' >"; 
echo "<option value = ''>";
while($row = mysqli_fetch_array($result)){
    echo "<option value = '" . $row['account_name'] . "'>" . $row['account_name'] . "</option>";
}
echo "</select>";
?>
<br><br>
Select start date:<br>
<input type = "date" name = "sdate" id = "sdate" value = ""/>
<div align = "center">
Select end date:<br>
<input type = "date" name = "edate" id = "edate" value = ""/><br><br>
<input type = "submit" name = "submit" id = "submit" value = "Submit"  />

这是我的第一组代码

(if(isset($_GET['submit']) || isset($_GET['page'])){ ...
</form>

0 个答案:

没有答案