我的問題是讓分頁工作正常。
因爲我有一個$ page = $ POST _ [「zain」]用於接收記錄,所以分頁時出現問題,它只顯示第一頁的結果。
這裏是我的代碼
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="zain.php" method="post">
Topic: <input type="text" name="topic"><br />
<br />
Name: <input type="text" name="name"><br /><br />
Attendance: <input type="text" name="attendance"><br />
<br />
<input type="reset" name="reset">
<input type="submit" id = "go" name="submit" value="Go">
</form>
<?php
$user = 'root';
$password = 'zz224466';
$db = 'Zain';
// Create connection
$conn = mysqli_connect('localhost', $user, $password, $db);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "";
mysqli_select_db($conn, "zain");
//$sql = "CREATE TABLE Lectures(Topic varchar(20), Name varchar(20), Attendence int)";
$sqli = "INSERT INTO lectures(Topic , Name , Attendence) VALUES('$_POST[topic]','$_POST[name]','$_POST[attendance]')";
mysqli_query($conn, $sqli);
////////////////////////// For print DATABASE on the screen using PAGINATION ////////////////////////////////////////
mysqli_select_db($conn, "zain");
if(isset($_GET['page'])){
if($page=="" || $page=="1")
{
$page1 = 0;
}
else
{
$page1 = ($page*5)-5;
}
} 的$ database = 「SELECT * FROM講座限制$ page1,5」;
$print = mysqli_query($conn, $dataBase);
while ($record = mysqli_fetch_array($print))
{
echo $record['Topic'];
echo "</br>";
}
$selectDatabase = "SELECT * FROM lectures";
$res1 = mysqli_query($conn, $selectDatabase);
$countRow = mysqli_num_rows($res1);
$a = $countRow/5;
$a = ceil($a);
echo "<br>" . $a;
echo "</br> </br>";
for($b=1; $b<=$a; $b++)
{
?><a href ="zain.php?page=<?php echo $b; ?>" style="text-decoration: none"><?php echo $b . " ";?></a><?php
}
mysqli_close($conn);
?>
</body>
</html>
你還需要的是'$ POST _ [ 「Zain公司」]在接下來的頁面太'變量。更好地使用'$ _GET'變量 – roullie
我應該創建新頁面嗎? –
不!你只需要使用$ page = $ _GET [「zain」];而不是$ page = $ _POST [「zain」]; –