przejście do następnej strony

0

Cześć
Proszę o pomoc. Działa mi wybór oraz wyświetlanie wybranych informacji, ale nie działa mi przechodzenie stron między jedną a drugą. W zamyśle miałem, że na każdej stronie będzie 5 rekordów.
Pojawia mi się na pierwszej stronie 5 rekordów i to jest ok, ale jak klikam na stronę druga lub ostatnią to mnie przekierowuje na index.php
Pierwsze strona pojawia mi się wp-content/themes/Dokumenty/standar_show/showAll_category.php i to działa, ale gdy wybieram druga lub następną to przekierowuje mnie na stronę /wp-content/themes/Dokumenty/standar_show/index.php?page=2.
Co robię źle. Poniżej przesyłam kody

<?php
session_start();
if($_POST){
	
	if(isset($_POST['cat_id_select'])){
	$_SESSION['cat_id_select'] = $_POST['cat_id_select'];	
	$_POST['cat_id_select'] = null;	
	header('Location: /wp-content/themes/Dokumenty/standar_show/showAll_category.php');
	}
	
	if(isset($_POST['subcat_id_select'])){
	$_SESSION['subcat_id_select'] = $_POST['subcat_id_select'];	
	$_POST['subcat_id_select'] = null;	
	header('Location: /wp-content/themes/Dokumenty/standar_show/showAll_subcategory.php');
	}
}


if(!($_SESSION['log'])){
header("Location: /wp-content/themes/Dokumenty/index.php?error=4");
exit;
}

?>



<?php
include_once 'config/core.php';
 
include_once 'config/database.php';
include_once 'objects/instruction.php';
include_once 'objects/category.php';
 
$database = new Database();
$db = $database->getConnection();
 
$instruction = new Instruction($db);
$category = new Category($db);
 
$page_title = "Instrukcje i regulamin";
include_once "layout_header.php";
 
$stmt = $instruction->readAll($from_record_num, $records_per_page);
 
$page_url = "index.php?";
 
$total_rows=$instruction->countAll();
 
include_once "read_template.php";
 
include_once "layout_footer.php";
?>

showAll_category.php

<?php
session_start();


if(!($_SESSION['log'])){
header("Location: /wp-content/themes/Dokumenty/index.php?error=4");
exit;
}

?>
<?php
// core.php holds pagination variables
include_once 'config/core.php';
 
// include database and object files
include_once 'config/database.php';
include_once 'objects/instruction.php';
include_once 'objects/category.php';
 
// instantiate database and user object
$database = new Database();
$db = $database->getConnection();
 
$instruction = new Instruction($db);
$category = new Category($db);
 
$page_title = "Wszystkich instrukcji/regulaminów";
include_once "layout_header.php";
 
// query users
$stmt = $instruction->readAllCategory($from_record_num, $records_per_pagee);
 
// specify the page where paging is used
$page_url = "index.php?";
 
// count total rows - used for pagination
$total_rows=$instruction->countAllCategory();
 
// read_template.php controls how the user list will be rendered
?>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<?php

echo "<div class='right-button-margin'>";
    echo "<a href='index.php' class='btn btn-primary pull-right'>";
    echo "<span class='glyphicon glyphicon'></span> Powrót";
    echo "</a>";
echo "</div>";

if($total_rows>0){
 echo "<div>";
    echo "<table class='table table-hover table-responsive table-bordered'>";
        echo "<tr>";
            echo "<th>Nazwa</th>";
            echo "<th>Data</th>";
            echo "<th>Funkcja</th>";
        echo "</tr>";
 
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
 
            extract($row);
            echo "<tr>";
			echo "<td>{$name}</td>";
			echo "<td>{$modified}</td>";
		
                echo "<td>";
 
                    echo "<a href='read_one.php?id={$id}' class='btn btn-primary left-margin'>";
                        echo "<span class='glyphicon glyphicon-list'></span> Odczyt";
                    echo "</a>";
                echo "</td>";
            echo "</tr>";

			}
		echo "</table>";
	echo "</div>";	
    include_once 'paging.php';
 }
// tell the user there are no users
else{
    echo "<div class='alert alert-danger'>Nie znaleziono instrukcji/regulaminów</div>";
}
?>	
 <?php
// layout_footer.php holds our javascript and closing html tags
include_once "layout_footer.php";
?>

paging.php



<?php
echo "<ul class=\"pagination\">";
 
// button for first page
if($page>1){
    echo "<li><a href='{$page_url}' title='Go to the first page.'>";
        echo "First Page";
    echo "</a></li>";
}
 
// count all users in the database to calculate total pages
$total_pages = ceil($total_rows / $records_per_page);
 
// range of links to show
$range = 2;
 
// display links to 'range of pages' around 'current page'
$initial_num = $page - $range;
$condition_limit_num = ($page + $range)  + 1;
 
for ($x=$initial_num; $x<$condition_limit_num; $x++) {
 
    // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages'
    if (($x > 0) && ($x <= $total_pages)) {
 
        // current page
        if ($x == $page) {
            echo "<li class='active'><a href=\"#\">$x <span class=\"sr-only\">(current)</span></a></li>";
        }
 
        // not current page
        else {
            echo "<li><a href='{$page_url}page=$x'>$x</a></li>";
        }
    }
}
 
// button for last page
if($page<$total_pages){
    echo "<li><a href='" .$page_url . "page={$total_pages}' title='Last page is {$total_pages}.'>";
        echo "Last Page";
    echo "</a></li>";
}
 
echo "</ul>";
?>
0

Może za mało się znam na wordpresie, ale czy ten kod jest normalny? @czysteskarpety Ty może coś więcej powiesz :)

Moim zdaniem dopisałeś sobie parę linijek do wordpressa i dziwisz się, że nie działa.

Napisałeś że na pierwszej stronie pojawia Ci się wp-content/themes/Dokumenty/standar_show/showAll_category.php - masz to w url'u czy tak po prostu ustawiłeś ten widok/stronę, że ma Ci się ładować jako główna strona (lub np jest dostępna pod index.php).

Napisz lepiej jak wyglądają Twoje linki do stron nr 1 i 2. Skoro chcesz mieć stronicowanie to link powinien mieć jakiś &page=2.. czy coś takiego.

0

Stronicowanie mam w pliku: paging.php


<?php
echo "<ul class=\"pagination\">";

// button for first page
if($page>1){
    echo "<li><a href='{$page_url}' title='Go to the first page.'>";
        echo "First Page";
    echo "</a></li>";
}

// count all users in the database to calculate total pages
$total_pages = ceil($total_rows / $records_per_page);

// range of links to show
$range = 2;

// display links to 'range of pages' around 'current page'
$initial_num = $page - $range;
$condition_limit_num = ($page + $range)  + 1;

for ($x=$initial_num; $x<$condition_limit_num; $x++) {

    // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages'
    if (($x > 0) && ($x <= $total_pages)) {

        // current page
        if ($x == $page) {
            echo "<li class='active'><a href=\"#\">$x <span class=\"sr-only\">(current)</span></a></li>";
        }

        // not current page
        else {
            echo "<li><a href='{$page_url}page=$x'>$x</a></li>";
        }
    }
}

// button for last page
if($page<$total_pages){
    echo "<li><a href='" .$page_url . "page={$total_pages}' title='Last page is {$total_pages}.'>";
        echo "Last Page";
    echo "</a></li>";
}

echo "</ul>";
?>
0
axelbest napisał(a):

Może za mało się znam na wordpresie, ale czy ten kod jest normalny?

Zaiste :)
Wordpress bazuje na action/hooks api, czyli w tym przypadku add_action();
https://www.ironistic.com/using-php-sessions-in-wordpress/
Być może czysty kod PHP zadziała, ale czy zawsze prawidłowo (z pluginami również) to raczej na produkcje bym tego nie pchał.

0

stronicowanie nie działa nawet jak uruchamiam stronę na xampie

1 użytkowników online, w tym zalogowanych: 0, gości: 1