Jump to content

[SOLVED] pagination, no next result


myrok24

Recommended Posts

PLease can someone help me with my issue.

I have this pagination in my file. But somehow it's not getting the right values or something for the next, previous e hyperlinks...

 

my code:

<? if (isset($_GET['pagina'])) {
   $pagina = $_GET['pagina'];
} else {
   $pagina = 1;
} 

$query = "SELECT count(*) 
        FROM 
            upload  
        WHERE
        klant = '".mysql_real_escape_string($_GET['klant'])."'
";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 1;
$lastpage      = ceil($numrows/$rows_per_page);

$pagina = (int)$pagina;
if ($pagina > $lastpage) {
   $pagina = $lastpage;
} 
if ($pagina < 1) {
   $pagina = 1;
} 




$limit = 'LIMIT ' .($pagina - 1) * $rows_per_page .',' .$rows_per_page;


$query = "
        SELECT 
            id, 
            name, 
            label, 
            tekst, 
            category, 
            klant, 
            DATE_FORMAT(datum, '%d-%m-%Y') AS nl_datum 
        FROM 
            upload  
            WHERE       klant = '".mysql_real_escape_string($_GET['klant'])."'

    $limit";    
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

    while ($myrow = mysql_fetch_assoc($result))

{


?>


<!-- ### WERK TONEN ######-->
<div style="width:500px;background-color:#0CF; float:right">
<div >
    <div>
        <h3> <? echo $myrow['klant'] ?></h3>
        <p class="newsdate">Geplaatst op: <? echo $myrow['nl_datum'] ?></p>
                <p class="newsdate">Middel: <? echo $myrow['category'] ?></p>
                <p class="newsdate">Opdracht: <? echo $myrow['label'] ?></p>


        <? echo '<img class=plaatje src="image/' . $myrow['name'] . '" />' ; ?>
        <p class="newstext"> <? echo ($myrow['tekst']) ?> </p>   
    </div>
</div>

</div>


<?php 
    } // (else..) aflsuiten..
?>


<?

if ($pagina == 1) {
   echo " EERSTE VORIGE";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pagina=1'>EERSTE</a> ";
   $prevpage = $pagina-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pagina=$prevpage'>VORIGE</a> ";
} 

echo " ( pagina $pagina / $lastpage ) ";

if ($pagina == $lastpage) {
   echo " VOLGENDE LAATSTE ";
} else {
   $nextpage = $pagina+1;
  // echo " <a href='{$_SERVER['PHP_SELF']}?pagina=$nextpage'>VOLGENDE</a> ";
   
echo " <a href='index.php?pagina=klanten&klant={$_GET['klant']}&pagina=$nextpage'>VOLGENDE</a> "; ?> //new one..
   
   echo " <a href='{$_SERVER['PHP_SELF']}?pagina=$lastpage'>LAATSTE</a> ";
}

?>

 

I changed one "next" hyperlink with a better url. but still nothing in the output when i click it.

Strange thing is that the total record count is correct and when i changed the max resultst, the records are al there. So the only thing that's not working are the buttons for more..

It's not getting the right info?..

thnx in advance!

 

example: http://blikvoer.com/temp/samtest/index.php?pagina=klanten&klant=Anwb --> second "volgende" link..

Link to comment
Share on other sites

Hey there,

 

You have the right idea here:

echo " <a href='index.php?pagina=klanten&klant={$_GET['klant']}&pagina=$nextpage'>VOLGENDE</a> "; ?> 

 

Just update it to:

echo " <a href='index.php?klant={$_GET['klant']}&pagina=$nextpage'>VOLGENDE</a> "; ?> 

 

Also be sure to put the klant={$_GET['klant']} on all of your pagination links. :)

Link to comment
Share on other sites

solved.. final code:

 


<? if (isset($_GET['selectie'])) {
   $selectie = $_GET['selectie'];
} else {
   $selectie = 1;
} 

$query = "SELECT
		count(*) 
        FROM 
		upload  
        WHERE
       		 klant = '".mysql_real_escape_string($_GET['klant'])."'
";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 1;
$lastpage      = ceil($numrows/$rows_per_page);

$selectie = (int)$selectie;
if ($selectie > $lastpage) {
   $selectie = $lastpage;
} 
if ($selectie < 1) {
   $selectie = 1;
} 
$limit = 'LIMIT ' .($selectie - 1) * $rows_per_page .',' .$rows_per_page;



$query = "
	SELECT 
            id, 
            name, 
            label, 
            tekst, 
            category, 
            klant, 
            DATE_FORMAT(datum, '%d-%m-%Y') AS nl_datum 
        FROM 
            upload  
        WHERE
          	 klant = '".mysql_real_escape_string($_GET['klant'])."'

	$limit
	";	
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

while ($myrow = mysql_fetch_assoc($result))

{


?>


<!-- ### WERK TONEN ######-->
<div style="width:500px;background-color:#0CF; float:right">
<div >
    <div>
        <h3> <? echo $myrow['klant'] ?></h3>
        <p class="newsdate">Geplaatst op: <? echo $myrow['nl_datum'] ?></p>
                <p class="newsdate">Middel: <? echo $myrow['category'] ?></p>
			<p class="newsdate">Opdracht: <? echo $myrow['label'] ?></p>


        <? echo '<img class=plaatje src="image/' . $myrow['name'] . '" />' ; ?>
        <p class="newstext"> <? echo ($myrow['tekst']) ?> </p>   
    </div>
</div>

</div>




<!-- ### PAGINERING: volgende/totaal/volgende ######-->
<div style="background-color:yellow">
<?

if ($selectie == 1) {

   	echo "<FONT color=grey size=1>VORIGE</FONT>"; //tekst als er geen vorige of eerste is
} 	else {
//	echo " <a href='index.php?pagina=klanten&klant={$_GET['klant']}&selectie=1'> <FONT size=1>EERSTE</FONT></a> "; //eerste optie
$prevpage = $selectie-1;
echo " <a href='index.php?pagina=klanten&klant={$_GET['klant']}&selectie=$prevpage'><FONT size=1>VORIGE</FONT></a> "; //vorige optie

} 

echo " <FONT size=1> || OPDRACHT <strong> $selectie </strong> / $lastpage || </FONT> ";


if ($selectie == $lastpage) {
   	echo "<FONT color=grey size=1>VOLGENDE</FONT>";  //tekst als er geen volgende of laatste is
} 	else {
$nextpage = $selectie+1;
echo " <a href='index.php?pagina=klanten&klant={$_GET['klant']}&selectie=$nextpage'><FONT size=1>VOLGENDE</FONT></a> ";    //volgende optie
//	echo " <a href='index.php?pagina=klanten&klant={$_GET['klant']}&selectie=$lastpage'><FONT size=1>LAATSTE</FONT></a> ";    //laatste optie
}

?></br>KLANTEN
</div>
<!-- ### PAGINERING EINDE ####-->



<?php 
} // (while..) aflsuiten..
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.