problema con l'Undefined index per una $_GET

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
Ciao, ho questo piccolo codice che ho ripreso in mano.. ma non ricordo dove devo mettere questo codice:
$page = (int)($_GET["page"])>0 ? (int)$_GET["page"] : 1;
per far che se uno mano mette l'url del browser non viene indicato nessun errore.

l'if in questione è questo:
PHP:
//Set the $page variable
if(!isset($page)){
        $page = 1;
}else{
        $page = $_GET["page"];
        
} 
$page = (int)($_GET["page"])>0 ? (int)$_GET["page"] : 1;

ora ho messo cosi.
ma quando digito l'indirizzo senza parametro $get , mi da l'errore: Notice: Undefined index: page , che vorrei risolvere.

qualcuno sa qualcosa?

grazie mille e buona giornata.
 
ciao
prova semplicemente cosi
PHP:
<?php
//Set the $page variable
if(!isset($page)){
	$page = 1;
}else{
	$page = (int)($_GET["page"])>0 ? (int)$_GET["page"] : 1;  
} 
?>
 
ciao ho provato l'errore va via.. ma non funziona la paginazione che ti incollo tutto il codice dove ho recuperato in una usb key.. perché ho avuto problemi con il pc e ho perso tutto le ultime cose che avevo fatto.

PHP:
//The directory to your pages folder, with trailing slash
$dir = "../pages/";

//Set the extensions you want to load, seperate by a comma.
$extensions = "php";

//Set the number of pages you want to display per page
$pagesPerPage = 1;


//Set the $page variable 
if(!isset($page)){ 
    $page = 1; 
}else{ 
    $page = (int)($_GET["page"])>0 ? (int)$_GET["page"] : 1;   
}  


//Load all pages into an array
$pages = glob($dir."*.{".$extensions."}", GLOB_BRACE);

//Count the number of pages
$totalpages = count($pages);

//Get the total pages
$totalPages = ceil($totalpages / $pagesPerPage);

//Make sure the page you are on is not greater then the total pages available.
if($page > $totalPages){
        //Set the currnet page to the total pages.
        $page = $totalPages;
}

//Now find where to start the loading from
$from = ($page * $pagesPerPage) - $pagesPerPage;

//Now start looping
for($i = $from; $i < ($from + $pagesPerPage); $i++){
        //We need to make sure that its within the range of totalpages.
        if($i < $totalpages){
                //Now we can display the image!
                echo "<a href='admin_pages.php?action=edit&file=".basename($pages[$i],'.php')."'>".basename($pages[$i],'.php')."</a><br />";
        }
}

//Now to display the page numbers!
for($p = 1; $p <= $totalPages; $p++){
        if($p == $page){
                $tmp_pages[] = "<strong>{$p}</strong>";
        }else{
                $tmp_pages[] = "<a href='?page={$p}'>{$p}</a>";
        }
}
//Now display pages, seperated by a hyphon.
echo "<br />" . implode(" - ", $tmp_pages);

ti ringrazio molto.

buona serata.
 
ciao
sei sicuro che non funzioni come l'ho messo io?
l'ho provato e mi da
in alto il nome del file
sotto le pagine es:
file_1
1-2-3- ecc...

cliccando su altra pagina cambia il nome del file
 
si, funziona anche a me ..

ma mi da il notice quando non c'è $_GET["page"] ovvero index.php?page=1 etc..
come faccio ?

grazie mille.
 

Discussioni simili