Hallo allemaal!

op http://81.30.70.233/~dnp/ staan heel veel items, en zoals je ziet levert dat tot nu toe 32 pagina's op, en dat worden er steeds meer. Onhandig! Mooier zou zijn als je ziet

(1) | 2 | 3 | 4 | 5 >>

en mocht je al op pagina 4 geklikt hebben:

<< 2 | 3 | (4) | 5 | 6 >>

maar hoe?
[google]pagination[/google]
Had ik uiteraard al naar gezocht, maar ik kwam er niet uit.. Heb je een concretere tip?

alvast bedankt
ik heb ooit zoiets geschreven, heel specifiek voor 1 website, geen commentaar toegevoegd, en nu niet de tijd om het wat gebruiks-vriendelijker te maken,

hopelijk geeft het je een paar goeie ideeen,

EDIT:
$num is hier de huidige 'actieve' pagina

<?php
$max_numbers = 7;
$p = 1;

$i = 1;
while($num - $i > 0 && $i < ceil($max_numbers / 2)){
$p = $num - $i;
$i ++;
}

if(ceil($totaal / 5) < $p + $max_numbers - 1){
$eind = ceil($totaal / 5);
$p = $eind - (ceil($max_numbers / 2) + 2); // de ' + 2' moet aangepast worden indien $max_nummers veranderd word, (1 indien max_numbers 5 is bv)
if($eind < $p + $max_numbers - 2){
$p ++;

if($eind == $num)
$p --;
}

} else
$eind = $p + $max_numbers - 1;

while($p < 1)
$p ++;

$start = $p;

if($totaal < 1)
echo "niks gevonden";
else {
$eerste_pagina = ($num - 1) * $limiet;

$laatste_pagina = $num * $limiet;
if($laatste_pagina > $totaal)
$laatste_pagina = $totaal;

echo $eerste_pagina + 1, " t/m ", $laatste_pagina, " van de ", $totaal, " gevonden verkoopopdrachten");
}

while($p <= $eind){
if($p == $num)
echo $p;
else
echo '<a href="http://www.site.com/link_naar_de_pagina/'; . $p . '">' . $p . '</a>';

if($p < $eind)
echo '| ';

$p ++;
}
?>
Ik moest iets soorts geleik hebben. Als je het op meerdere plaatsen wilt gebruiken op 1 website zou ik hem ombouwen met functies. Ben ik ook nog van plan maar vandaag geen tijd meer voor. :p Sorry voor het Engels, is iets voor mezelf en dan doe ik niet aan Nederlands.


 <?php

    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Settings.
    --------------------------------------------------------------------------------------------------------------------------*/    

    /*---- INFO! ---->
    
        Make sure the menu length is an uneven number.
                
    */
    
    #| Maximum length of the menu.
    
        $menu_length = 5;
    
    
    #| Menu's divider.
    
        $menu_divider = ' | ';


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Page count.
    --------------------------------------------------------------------------------------------------------------------------*/                

        // Hier moet je je eigen code plaatsen voor het het berekenen van het aantal pagina's,
        
            $page_count = 32;


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Validate the supplied current page. " $_GET['page'] "
    --------------------------------------------------------------------------------------------------------------------------*/                
            
    #| Current page.
    
        $current_page = (isset($_GET['page']) and in_array($_GET['page'], range(1, $page_count))) ? $_GET['page'] : 1 ;


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Menu's range.
    --------------------------------------------------------------------------------------------------------------------------*/    

    /*---- INFO! ---->
    
        Calculate the menu's range.
                
    */

    #| Calculate the menu's middle point.
    
        $mid_point = floor($menu_length / 2 );


    #| Calculate the menu's range.
    
        if($page_count < $menu_length){
        
        #| Not enough pages for the fancy stuff.
        
            $menu_range = range(1, $page_count);
            
        }
        elseif($current_page > ($page_count - $mid_point)){
            
        #| Last couple of pages.
        
            $menu_range = range(($page_count - $menu_length) , $page_count);
            
        }
        elseif($current_page > $mid_point){
        
        #| Middle pages.
        
            $menu_range = range(($current_page - $mid_point), ($current_page + $mid_point));
            
        }
        else{
        
        #| First couple of pages.
        
            $menu_range = range(1, $menu_length);
            
        }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pagination :: Demo</title>
</head>

<body>
<?php

    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Video's weergeven.
    --------------------------------------------------------------------------------------------------------------------------*/    

		// Hier je while loop met video's.
		

    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Previous page
    --------------------------------------------------------------------------------------------------------------------------*/    
    
        if($current_page > 1){
            
            echo '<a href="?page='.($current_page - 1).'"><<</a> ';
        }

    
    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Numeric menu.
    --------------------------------------------------------------------------------------------------------------------------*/    

    #| Set " $menu " array for storing all the menu's items.
    
        $menu = array();
        
    
    #| Create all the menu's items.
    
        foreach($menu_range as $page){
            
            $menu[] = ($page == $current_page) ? '(<a href="?page='.$page.'">'.$page.'</a>) ' : '<a href="?page='.$page.'">'.$page.'</a>' ;
        }
        

    #| Display the menu.

        echo implode($menu_divider, $menu);

    
    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Next page.
    --------------------------------------------------------------------------------------------------------------------------*/    

        if($current_page < $page_count){
            
            echo ' <a href="?page='.($current_page + 1).'">>></a>';
        }
    
?>
</body>
</html> 
Beiden zien er mooi uit, maar waar plaats je dan de data die weergegeven moet worden? Overigens heb ik op de link die ik bovenaan dit onderwerp gaf deze code:




<?php
# 10-10-2006
# pagina nummering v1.0
# G. de Rover
# GDRmedia
# [email protected]
//
// welke pagina er geshowed moet worden
$pag        = $_GET['pag'];
// eerste bezoek moet 0 zijn.
if($pag == '1' || $pag == 1){
    $pag = 0;
}
// het aantal resultaten per pagina.
$showRecords= 3;
//
// connectie settings
$myServer    = 'localhost';
$myDataBase    = 'xxx';
$myUser        = 'xxxx';
$myPass        = 'xxxx';
//
$myConn = mysql_connect($myServer, $myUser, $myPass); 
$select = mysql_select_db($myDataBase, $myConn);
//
$query = 'SELECT * FROM dnp2 ORDER BY Datum DESC'; 
$results = mysql_query($query) or die(mysql_error()); 
$num_rows = mysql_num_rows($results);
//
$pages = $num_rows / $showRecords;
//
if($pages>1){
    $myPage = $pag * $showRecords;
    //
    $query = 'SELECT * FROM dnp2 ORDER BY Datum DESC LIMIT '.$myPage.', '.$showRecords; 
    $results = mysql_query($query) or die(mysql_error()); 
}
//output:
echo '<div class="divpaginatelling">';
// checkt of er uberhaubt wel meerdere pagina's zijn.
if($pages > 1){
    for($i=1; $i<=floor($pages); $i++){
        echo ' | <a href='.$_SERVER['PHP_SELF'].'?pag='.$i.'>'.$i.'</a>';
    }
    echo ' |<br/></div><br/>';
}
// spuug de gewenste data uit.
while ($row = mysql_fetch_array($results)) {

   echo ' <div class="geheel">

			<div class="linkerkolom">

				<div class="bovenlinks">
                			<div class="titel"><div class="id">( '.$row['ID'].' ) </div> '.$row['Titel'].'</div>
							<div class="datum">'.$row['Datum'].'</div> 

				</div><br>

				<div class="onderlinks">

                			<div class="bericht"><br><b>'.$row['Plaats'].'</b> - '.$row['Bericht'];

ETC.... 
Als ik op http://81.30.70.233/~dnp/ kijk heb je het MySQL gedeelte al. Ik heb het commentaar iets aangepast, je kunt mijn code gewoon als een nieuwe pagina opslaan en bekijken voor de werking, je moet het iets uit elkaar halen en in jouw website bouwen. maar zo onduidelijk kan het toch niet zijn?
Nou eerlijk gezegd raak ik helemaal in de war van alle codes. Of ik krijg een error of ik krijg helemaal niks van die code te zien...
Errors altijd even posten. Eventueel met enkele relevante coderegels.
Foutcode:

Warning: Division by zero in /home/dnp/domains/dnp.nu/public_html/tester.php on line 193

en bovendien pakt ie de ID niet, want de mappen worden ook niet correct uitgelezen (de mapnamen zijn gelijk aan de idnamen. Toch leest hij wel 32 pagina's, wat precies klopt met het orginele script...



http://81.30.70.233/~dnp/tester.php

<?php

    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Settings.
    --------------------------------------------------------------------------------------------------------------------------*/    

    /*---- INFO! ---->
    
        Make sure the menu length is an uneven number.
                
    */
    
    #| Maximum length of the menu.
    
        $menu_length = 5;
    
    
    #| Menu's divider.
    
        $menu_divider = ' | ';


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Page count.
    --------------------------------------------------------------------------------------------------------------------------*/                

        // Hier moet je je eigen code plaatsen voor het het berekenen van het aantal pagina's,
        
            $page_count = 32;


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Validate the supplied current page. " $_GET['page'] "
    --------------------------------------------------------------------------------------------------------------------------*/                
            
    #| Current page.
    
        $current_page = (isset($_GET['page']) and in_array($_GET['page'], range(1, $page_count))) ? $_GET['page'] : 1 ;


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Menu's range.
    --------------------------------------------------------------------------------------------------------------------------*/    

    /*---- INFO! ---->
    
        Calculate the menu's range.
                
    */

    #| Calculate the menu's middle point.
    
        $mid_point = floor($menu_length / 2 );


    #| Calculate the menu's range.
    
        if($page_count < $menu_length){
        
        #| Not enough pages for the fancy stuff.
        
            $menu_range = range(1, $page_count);
            
        }
        elseif($current_page > ($page_count - $mid_point)){
            
        #| Last couple of pages.
        
            $menu_range = range(($page_count - $menu_length) , $page_count);
            
        }
        elseif($current_page > $mid_point){
        
        #| Middle pages.
        
            $menu_range = range(($current_page - $mid_point), ($current_page + $mid_point));
            
        }
        else{
        
        #| First couple of pages.
        
            $menu_range = range(1, $menu_length);
            
        }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

	<head>
		<title> DNP.NU beta 3</title>
		<LINK REL=StyleSheet HREF="style1.css" TYPE="text/css" MEDIA=screen>
		<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<SCRIPT>
<!-- PopUp Link JavaScript Code Provided By: http://www.DesignerWiz.com - Development Resource & JavaScript Public Archive Center -->
function popUp(page,PWidth,PHeight,id) {
 eval("designerwiz"+id+"=window.open('"+page+"','designerwiz1','toolbar=0,scrollbars=1,location=0,status=1,menubars=0,resizable=0,width="+PWidth+",height="+PHeight+"')")
eval;("wiz"+id+".window.moveTo((screen.width/2)-(PWidth/2),(screen.height/2)-(PHeight/2))")
}
</SCRIPT>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>

	</head>
	<body>


<div class="container">



<div class="midden2">
<div class="midden">


	<div class="header">
		<img src="layout/img/header.png" alt="DNP.NU">
	</div>

	<div class="divmenu">
		 <A HREF="javascript:popUp('upload.php',500,250,1);"><img src="layout/img/uploadbutton.png" border=0 alt="Upload jouw video op DNP.NU" align="right"></a>
	</div>


<body>
<?php

// connectie settings
$myServer    = 'localhost';
$myDataBase    = 'xxx';
$myUser        = 'xxx';
$myPass        = 'xxx';
//
$myConn = mysql_connect($myServer, $myUser, $myPass); 
$select = mysql_select_db($myDataBase, $myConn);
//
$query = 'SELECT * FROM dnp2 ORDER BY Datum DESC'; 
$results = mysql_query($query) or die(mysql_error()); 
$num_rows = mysql_num_rows($results);
//


    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Video's weergeven.
    --------------------------------------------------------------------------------------------------------------------------*/    

        // Hier je while loop met video's.
        

    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Previous page
    --------------------------------------------------------------------------------------------------------------------------*/    
    
        if($current_page > 1){
            
            echo '<a href="?page='.($current_page - 1).'"><<</a> ';
        }

    
    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Numeric menu.
    --------------------------------------------------------------------------------------------------------------------------*/    

    #| Set " $menu " array for storing all the menu's items.
    
        $menu = array();
        
    
    #| Create all the menu's items.
    
        foreach($menu_range as $page){
            
            $menu[] = ($page == $current_page) ? '(<a href="?page='.$page.'">'.$page.'</a>) ' : '<a href="?page='.$page.'">'.$page.'</a>' ;
        }
        

    #| Display the menu.

        echo implode($menu_divider, $menu);

    
    /*--------------------------------------------------------------------------------------------------------------------------    
    (§) Pagination | Next page.
    --------------------------------------------------------------------------------------------------------------------------*/    

        if($current_page < $page_count){
            
            echo ' <a href="?page='.($current_page + 1).'">>></a>';
        }
		
		$pages = $num_rows / $showRecords;
//
if($pages>1){
    $myPage = $pag * $showRecords;
    //
    $query = 'SELECT * FROM dnp2 ORDER BY Datum DESC LIMIT '.$myPage.', '.$showRecords; 
    $results = mysql_query($query) or die(mysql_error()); 
}


   echo ' <div class="geheel">

			<div class="linkerkolom">

				<div class="bovenlinks">
                			<div class="titel"><div class="id">( '.$row['ID'].' ) </div> '.$row['Titel'].'</div>
							<div class="datum">'.$row['Datum'].'</div> 

				</div><br>

				<div class="onderlinks">

                			<div class="bericht"><br><b>'.$row['Plaats'].'</b> - '.$row['Bericht'];



	$dirname = "dnpnieuw/items/".$row['ID']."/downloads";

	$images = scandir($dirname);

	$ignore = Array(".", "..", ".txt", ".TXT");



	foreach($images as $curimg){

		if(!in_array($curimg, $ignore)) {

			echo '<br><a href="dnpnieuw/items/'.$row['ID'].'/downloads/'.$curimg.'">Download '.$curimg.'</a><br>'.PHP_EOL;
		}

	}     

echo '</div> 

				</div>

			</div>

			<div class="rechterkolom"><img src="layout/img/balkvideo.png" alt="Bekijk onderstaande video">';
					

	$dirname = "dnpnieuw/items/".$row['ID']."/flv/";

	$images = scandir($dirname);

	$ignore = Array(".", "..", ".txt", ".TXT");



	foreach($images as $curimg){

		if(!in_array($curimg, $ignore)) {

			echo '<object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000  
codebase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0
width=381 height=216 id=fullscreen align=middle> 
<param name="WMode" value="transparent"></param>
<param name=allowScriptAccess value=sameDomain/> 
<param name=movie value="flvplayer.swf/> 
<param name=quality value=high /> 
<param name=salign value=tl /> 
<param name=bgcolor value=#ffffff /> 
<param name="startimage" value="start_frame.jpg" />
	<param name="autoplay" value="0" />
	<param name="autoload" value="0" />
	<param name="buffer" value="5" />
	<param name="buffermessage" value="" />
	<param name="buffercolor" value="ffffff" />
	<param name="bufferbgcolor" value="858686" />
	<param name="buffershowbg" value="0" />
	<param name="title" value="20100214 Zwaag carnaval" />
	<param name="titlesize" value="20" />
	<param name="titlecolor" value="ffffff" />
	<param name="margin" value="0" />
	<param name="srt" value="0" />
	<param name="srtcolor" value="ffffff" />
	<param name="srtbgcolor" value="858686" />
	<param name="srtsize" value="11" />
	<param name="showstop" value="1" />
	<param name="showvolume" value="1" />
	<param name="showtime" value="1" />
	<param name="showplayer" value="autohide" />
	<param name="showloading" value="autohide" />
	<param name="showfullscreen" value="1" />
	<param name="showswitchsubtitles" value="0" />
	<param name="showmouse" value="autohide" />
	<param name="loop" value="0" />
	<param name="startimage" value="start_frame.jpg" />
	<param name="playercolor" value="858686" />
	<param name="loadingcolor" value="dddddd" />
	<param name="bgcolor" value="ffffff" />
	<param name="bgcolor1" value="ffffff" />
	<param name="bgcolor2" value="ffffff" />
	<param name="buttoncolor" value="ffffff" />
	<param name="buttonovercolor" value="c3c4c4" />
	<param name="slidercolor1" value="ffffff" />
	<param name="slidercolor2" value="cccccc" />
	<param name="sliderovercolor" value="c3c4c4" />
	<param name="loadonstop" value="0" />
	<param name="onclick" value="playpause" />
	<param name="onclicktarget" value="_blank" />
	<param name="ondoubleclick" value="fullscreen" />
	<param name="ondoubleclicktarget" value="_blank" />
	<param name="playertimeout" value="1500" />
	<param name="videobgcolor" value="000000" />
	<param name="volume" value="100" />
	<param name="shortcut" value="1" />
	<param name="playeralpha" value="100" />
	<param name="srturl" value="video.srt" />
	<param name="top1" value="0" />
	<param name="showiconplay" value="1" />
	<param name="iconplaycolor" value="ffffff" />
	<param name="iconplaybgcolor" value="dddddd" />
	<param name="iconplaybgalpha" value="25" />
	<param name="showtitleandstartimage" value="0" />
<param NAME=FlashVars VALUE="file=dnpnieuw/items/'.$row['ID'].'/flv/'.$curimg.'"> 
<embed wmode="transparent" src=flvplayer.swf FlashVars="file=dnpnieuw/items/'.$row['ID'].'/flv/'.$curimg.'" quality=high 
salign=tl bgcolor=#ffffff width=381 height=216 name=fullscreen 
align=middle allowScriptAccess=sameDomain type=application/x-shockwave-
flash pluginspage=http://www.macromedia.com/go/getflashplayer/> 
</object>'.PHP_EOL;

		}

	}     

echo '
					

<br>

				<img src="layout/img/balkfoto.png" alt="Bekijk onderstaande video">

					<div class="fotoalbum"><div class="fotoalbumcenter">';


	$dirname = "dnpnieuw/items/".$row['ID']."/foto/";

	$images = scandir($dirname);

	$ignore = Array(".", "..", ".txt", ".TXT");



	foreach($images as $curimg){

		if(!in_array($curimg, $ignore)) {

			echo '<a href="dnpnieuw/items/'.$row['ID'].'/foto/'.$curimg.'" rel="lightbox['.$row['ID'].']"><img img width=109 border=0 height=61 Hspace=5 Vspace=5 src="dnpnieuw/items/'.$row['ID'].'/foto/'.$curimg.'" alt="Foto: DNP.NU"></a>';
					
		}

	}     

echo '

				</div></div>

					

			</div>

</div><br>


            ';

?>




</div>
</body>
</html>
Division by zero

Je kan niet door 0 (nul) delen.

Reageren