リストは、他のリストの残りを取得するためのページネーションなしで 10 項目にとどまりました。これはひどいです。最初のコードは機能しましたが、2 番目のコードは機能しましたが、10 個の項目で停止しました。あなたは、私が既に持っていたいくつかのコードで行った ceil を試してみると言いました。 10 の項目が出てきたので、ここで少しイライラし始めています。
<DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Residential</title>
</head>
<body>
<section>
<form method="post" action="index.php?go" id="searchform">
<input type="text" id="sf" name="name" class="inputtext" >
<input type="submit" name="submit" id="sb" alt="Btn" value="GO">
</form>
</section>
<div class="results">
<?php
error_reporting(0);
if(isset($_POST['submit'])) {
if(isset($_GET['go'])) {
if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){ //"/[A-Z | a-z]+/",
$name=$_POST['name'];
//connect to the database
$db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("residential");
これが変更されたコードの始まりです
//////////pagination////////////
$sql=mysql_query("SELECT userId, FirstName, LastName FROM residentialbackup WHERE FirstName ='" . $name . "' OR LastName = '" . $name ."'");
//-count results
$numrows=mysql_num_rows($sql);
// Get the value of the last page in the pagination result set
$lastPage = ceil($numrows / $itemsPerPage);
$itemsPerPage = 10;
$page = $_GET['page'];
if (!$page) $page = 1;
$offset = ($page - 1) * $itemsPerPage;
$sql2=mysql_query("SELECT userId, FirstName, LastName FROM residentialbackup WHERE FirstName = '" . $name . "' OR LastName = '" . $name ."' LIMIT ". $offset . ", ". $itemsPerPage);
$paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1") {
// This shows the user what page they are on, and the total number of pages
$paginationDisplay .= 'Page <strong>' . $page . '</strong> of ' . $lastPage. ' ';
// If we are not on page 1 we can place the Back button
if ($page != 1) {
$previous = $page - 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $previous . '"> Back</a> ';
}
// Lay in the clickable numbers display here between the Back and Next links
$paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
// If we are not on the very last page we can place the Next button
if ($page != $lastPage) {
$nextPage = $page + 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $nextPage . '"> Next</a> ';
}
}
echo $paginationDisplay;
///////////////pagination end////////////
私はここまで立ち往生しています!
//echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>";
//-create while loop and loop through result set
while($row=mysql_fetch_array($sql2)) {
$FirstName =$row['FirstName'];
$LastName=$row['LastName'];
$userId=$row['userId'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"index.php?id=$userId\">" .$FirstName . " " . $LastName . " </a></li>\n";
echo "</ul>";
}
}
else {
echo "<p>Please enter a search query</p>";
}
}
/*
if(isset($_GET['by'])){
$name=$_GET['by'];
include "connectres.php";
//-query the database table
$sql="SELECT userId, FirstName, LastName FROM residentialbackup WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-count results
$numrows=mysql_num_rows($result);
echo "<p>" .$numrows . " results found for " . $name . "</p>";
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName =$row['FirstName'];
$LastName=$row['LastName'];
$userId=$row['userId'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"index.php?id=$userId\"> " . $LastName . " " . $FirstName . " </a></li>\n";
echo "</ul>";
}
}
*/
if(isset($_GET['id'])) {
$userId=$_GET['id'];
//connect to the database
include "connectres.php";
//-query the database table
$sql="SELECT * FROM residentialbackup WHERE userId=" . $userId;
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)) {
$FirstName =$row['FirstName'];
$LastName=$row['LastName'];
$PhoneNumber=$row['PhoneNumber'];
$Address=$row['Address'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<img src=\"../images/person.png\"/>" . $FirstName . " " . $LastName . " </li>\n";
echo "<li>" . "<img src=\"../images/tell.png\"/>" . " " . "<a href=tel:" . $PhoneNumber . ">" . $PhoneNumber . "</a></li>\n";
echo "<li>" . "<img src=\"../images/house.png\"/>" . " " . $Address . "</li>\n";
echo "</ul>";
}
}
?>
</div>
</div>
</body>
</html>