2016-08-08 109 views
0

我有一個php分頁頁面,用戶提交後提交搜索的東西,在第一頁查詢mysql是好的,但在NEXT頁面,我已經得到白色的空白頁。保持post變量在php分頁

以下是分頁代碼。

$_SESSION['nationality'] = $_POST['nationality']; 
$reclimit = 2; 

if(isset($_GET['page'])){ 
$page = $_GET['page']; 
} else { 
$page = 1; 
} 

$start = (($page-1) * $reclimit); 

$sql = "SELECT userid, name, LEFT(hkid, 4) as hkid, description, nationality, photo_1, photo_2, photo_3 FROM $tbl_name WHERE `nationality` LIKE '%$_SESSION[nationality]%'"; 
$records = $con->query($sql); 

$total = $records->num_rows; 
$tpages = ceil($total/$reclimit); 

$rec = "SELECT userid, name, LEFT(hkid, 4) as hkid, description, nationality, photo_1, photo_2, photo_3 FROM $tbl_name WHERE `nationality` LIKE '%$_SESSION[nationality]%' LIMIT $start, $reclimit"; 
$records = $con->query($rec); 

while ($row = mysqli_fetch_assoc($records)){ 

// Loop record 

} 

// Paging 
echo '<ul class="pagination pagination-lg">'; 
for($i=1; $i <= $tpages; $i++) { 
$active = $i == $page ? 'class="active"' : ''; 
echo "<li $active ><a href='$_SERVER[PHP_SELF]?page=" .$i. "'>" .$i. "</a></li>"; 
} 
echo '</ul>'; 

回答

0

這個工作對我來說:

<?php 
$limit =3; 
if (!isset($_GET['pg'])) { 
    $pg = 1; 
} else { 
    $pg = $_GET['pg']; 
} 
$start = ($pg - 1) * $limit;       
$sql = "SELECT * FROM tableName LIMIT $start , $limit"; 
?> 
+0

它不工作。 – kenleung

+0

plz在此處更新後添加代碼 –