Nedense benim arama script sadece ilk sayfa için sonuç ilk seti gösterecektir ama arama komut dosyası oluşturulur sonuçları görüntülenir olmayacak sonraki sayfaya pagination linke tıkladığınızda bu sorunu nasıl düzeltebilirim?
İşte benim PHP & olduğunu MySQL sayfalama kodu.
$x = '';
$construct = '';
if(isset($_POST['search'])) {
$search = $_POST['search'];
if(strlen($search) <= 2){
echo '';
} else {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
mysqli_select_db($mysqli, "sitename");
$search_explode = explode(" ", $search);
foreach($search_explode as $search_each) {
$x++;
if($x == 1){
$construct .= " article_content LIKE '%$search_each%' OR title LIKE '%$search_each%' OR summary LIKE '%$search_each%'";
} else {
$construct .= " OR article_content LIKE '%$search_each%' OR title LIKE '%$search_each%' OR summary LIKE '%$search_each%'";
}
}
$construct = "SELECT users.*, users_articles.* FROM users_articles
INNER JOIN users ON users_articles.user_id = users.user_id
WHERE $construct";
$run = mysqli_query($mysqli, $construct);
$search_term = mysqli_num_rows($run);
}
}
// Number of records to show per page:
$display = 10;
// Determine how many pages there are...
if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
$pages = mysqli_real_escape_string($mysqli, htmlentities(strip_tags($_GET['p'])));
} else { // Need to determine.
// Count the number of records:
$records = $search_term;
// Calculate the number of pages...
if ($records > $display) { // More than 1 page.
$pages = ceil ($records/$display);
} else {
$pages = 1;
}
} // End of p IF.
// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
$start = mysqli_real_escape_string($mysqli, htmlentities(strip_tags($_GET['s'])));
} else {
$start = 0;
}
// Make the links to other pages, if necessary.
if ($pages > 1) {
// Add some spacing and start a paragraph:
echo '<p>';
// Determine what page the script is on:
$current_page = ($start/$display) + 1;
//add this here... first will always be one
if ($current_page != 1) {
echo '<a href="search.php">First</a>';
}
// If it's not the first page, make a Previous button:
if ($current_page != 1) {
echo '<a href="search.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
}
//create the links
for ($i = max(1, $current_page - 3); $i <= min($current_page + 3, $pages); $i ++) {
if ($i != $current_page) {
echo '<a href="search.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
} else {
echo '<span>' . $i . '</span> ';
}
}
// If it's not the last page, make a Next button:
if ($current_page != $pages) {
echo '<a href="search.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';
}
//add this here... Last will always be one
if ($current_page != $pages) {
echo '<a href="search.php?s=' . ($display * ($pages - 1)) . '&p=' . $pages . '">Last</a>';
}
echo '</p>'; // Close the paragraph.
} // End of links section.
Burada PHP & parçasıdır MySQL arama kodu.
$x = '';
$construct = '';
if(isset($_POST['search'])) {
$search = $_POST['search'];
if(strlen($search) <= 2){
echo 'Your search term is too short!';
} else {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
mysqli_select_db($mysqli, "sitename");
$search_explode = explode(" ", $search);
foreach($search_explode as $search_each) {
$x++;
if($x == 1){
$construct .= " article_content LIKE '%$search_each%' OR title LIKE '%$search_each%' OR summary LIKE '%$search_each%'";
} else {
$construct .= " OR article_content LIKE '%$search_each%' OR title LIKE '%$search_each%' OR summary LIKE '%$search_each%'";
}
}
$construct = "SELECT users.*, users_articles.* FROM users_articles
INNER JOIN users ON users_articles.user_id = users.user_id
WHERE $construct";
$construct .= " LIMIT $start, $display";
$run = mysqli_query($mysqli, $construct);
$foundnum = mysqli_num_rows($run);
if ($foundnum == 0) {
echo 'Search term is too short!</p>No results found.';
} else {
echo 'results';
}
}
}