Jump to content
The Uniform Server Community
override

php?page=0

Recommended Posts

need a little help on this

 

<?php 
switch ($page) { 
case 0: 
echo "i equals 0"; 
break; 
case 1: 
echo "i equals 1"; 
break; 
case 2: 
echo "i equals 2"; 
break; 
default: 
echo "i is not equal to 0, 1 or 2"; 
} 

if(!$page) 
{ 
$page=1; 
} 
$max=5; 
$num=$page * $max - $max; 
$totalpage = ceil($lines/$max)+1; 

if ($page > 1) { 
	echo "<a href=\"?page=".($page-1)."\">[Prev]</a> \n"; 
} 
for($i=1; $i<$totalpage; $i++) { 
	if ($i == $page) { 
		echo "<b>[$i] </b>\n"; 
	} else { 
		echo "<a href=\"?page=".$i."\">[$i]</a> \n"; 
	} 
} 
if ($page < $totalpage-1) { 
	echo "<a href=\"?page=".($page+1)."\">[Next]</a>\n"; 
} 
?>


IPB Image

 

IPB Image

if you like this Uniform Server User Sing take em i do not mind share

IPB Image

 

IPB Image

Share this post


Link to post
Share on other sites

ok i got it to work but the next buttion is not working & it is skiping 1

like i got 0 < that dont show that is suppose to & 12345 showing & i got 678910 more pages

it dont go to them here is the code


IPB Image

 

IPB Image

if you like this Uniform Server User Sing take em i do not mind share

IPB Image

 

IPB Image

Share this post


Link to post
Share on other sites

u need to request the info

 

do this

 

switch ( $_REQUEST['page'] )

{

 

}


ATOMIC Web Hosting 2007 - 2011

Shared Hosting - Reseller Hosting - Dedicated Servers - Virtual Private Servers (Request Dedicated/VPS Servers via E-mail)

E-mail: sales@atomicwebhosting.com Website: http://www.atomicwebhosting.com/

Share this post


Link to post
Share on other sites

OO sorry here it is

<?php 
if(!$page) 
{ 
$page=0; 
} 
$max=5; 
$num=$page * $max - $max; 
$totalpage = ceil($lines = $max)+1; 

if ($page = 1) { 
	echo "<a href=\"$_SERVER[PHP_SELF]?index=".($page-1)."\">[Prev]</a> \n"; 
} 
for($i=1; $i <= $totalpage; $i++) { 
	if ($i == $page) { 
		echo "<b>[$i] </b>\n"; 
	} else { 
		echo "<a href=\"$_SERVER[PHP_SELF]?index=".$i."\">[$i]</a> \n"; 
	} 
} 
if ($page < $totalpage-1) { 
	echo "<a href=\"$_SERVER[PHP_SELF]?index=".($page+1)."\">[Next]</a>\n"; 
} 
?>


IPB Image

 

IPB Image

if you like this Uniform Server User Sing take em i do not mind share

IPB Image

 

IPB Image

Share this post


Link to post
Share on other sites

yea but is is like i sayed [Prev]12345[Next] & i got 678910 more pages & i dont get 0 in my switch


IPB Image

 

IPB Image

if you like this Uniform Server User Sing take em i do not mind share

IPB Image

 

IPB Image

Share this post


Link to post
Share on other sites

You may find this code of interest; I do admit it was written on the fly so forgive my use of variable names and inconstant comments. Think of it as a test piece I just hacked your code a little seemed a good base to start from. Save the code as index.php and play with some of the variables. I am no programmer hence never really understood the problem because there were no comments in your code. No reflection on you just my inability to understand the problem hence my little test piece may be an answer to an entirely different problem.

 

<html>
<head>
<title>Test page</title>
</head>
<body>
<?php
$currentPage = $_GET['index']; // page number to be displayed in multi-pages
$displayPage = $currentPage;   // this page will be highlighted in link list
$totalLines  = 43;			 // stored in file or database
$maxLinesPerPage = 2;		  // lines per page
$maxLinks = 8;				 // maximum number of direct links to display
// Need to know total number of pages based on data stored in either a file
// or database. This data is split into lines for example 5 lines per page.
// $totalLines	  = total lines in database or file
// $maxLinesPerPage = lines per page to be displayed.  
// $currentPage	 = current page being displayed variable re-used for adjustment
// $totalPages = total number of pages that can be displayed including the 
//			   last page that may be incomplete (partial page) 
$totalPages = intval($totalLines/$maxLinesPerPage); // Number of full pages
if ($totalLines % $maxLinesPerPage){				// is there a remainder
$totalPages = $totalPages + 1;					 // YES add partial page 
}
if(!$currentPage){  // was there a page request
 $currentPage=0;   // NO set the current page to 0
}
if($totalPages < $maxLinks){ // there are only direct links to display 
 $maxLinks = $totalPages;	// set max links to number of pages 
}
if($currentPage >($totalPages-$maxLinks)){ // can be the first link displayed  
 $currentPage = $totalPages-$maxLinks+1;  // reset accordingly 
}
if(($totalPages - $maxLinks) > $maxLinks){ // exceeded hence display a previous link
if($currentPage!=0){					  // however not if it is the first page 
 echo "<a href=\"$_SERVER[PHP_SELF]?index=".($currentPage -1)."\">[PREV]</a>\n"; 
}
}
for($i=$currentPage; $i!=($currentPage+$maxLinks); $i++){ //display link block 
if($i==$displayPage){ // set current page bold
 echo "<a href=\"$_SERVER[PHP_SELF]?index=".$i."\"><b>[$i]</b></a> \n"; 
}
else{ // display links in block
echo "<a href=\"$_SERVER[PHP_SELF]?index=".$i."\">[$i]</a> \n"; 
}
}
if(($totalPages-$currentPage) >= $maxLinks){ // exceeded hence display a next link
 echo "<a href=\"$_SERVER[PHP_SELF]?index=".($currentPage + $maxLinks)."\">[Next]</a>\n"; 
}
?>
</body>
</html>

 

Well have fun :)

Share this post


Link to post
Share on other sites

If the above meets your requirement you may find this of interest. Copy the code and name the file list2.php and play with the variables $outCount, $perPage and $numNavItems. I think I have commented out most of the code that is irrelevant for your application. It is easily adaptable for a MySQL database originally designed for use with the DigiOz Guestbook, which uses a file database architecture. My proposed solution can be enhanced so feel free to hack the code.

 


<html>
<head>
<title>Sliding NAV bar links</title>
</head>
<body>

<?php
//##################################################################################################
// Original code proposed for Digioz Guestbook REF DIGIOZ Beta17
// MPG V1.0.0  30-9-05
// Extracted and made generic for UniServer
// MPG V1.0.1 15-2-07
//##################################################################################################

//##################################################################################################
// This code produces a sliding navingation bar based on a list of items to be displayed. This data
// may be stotred in a database or in a file as in the Digioz Guest book. The type of information
// stored may be lines of text or a collection of data. This data will either fit onto one page or
// spread over several pages. To determine the number of pages we obtain the total
// number of enteries stored "$outCount" and define the number of enteries to display per page
// "$perPage". 

 $pageNum = $_GET['page'];  // current page number to be displayed in multi-pages
 if($pageNum <0) $pageNum=0; // prevent negative numbers entered by user do similar for higher numbers
 $outCount = 37;			// total number of enteries or items stored in file or database
						 // obtain this info from file or database 
 $perPage=2;				// Number of entries to show per page. Resonable default is 10.
 $singlePage = FALSE;	   // script sets this to true if enteries fit onto a single page

//##################################################################################################

$numberOfPages  = ceil($outCount/$perPage); // Total number of pages contained in our list

if ($outCount <= $perPage){				 // Do the list results fit on a single page 
 $start = 0;								// YES: first entery starts at array location 0
 $end = $outCount - 1;					  // set last entry location, note -1	
 $singlePage = TRUE;						// Set the single page indicator flag
}

else{									   // NO: Use default or users page selection.
  if($pageNum == 0){						// Did the user select a page to display 
 $pageNum = 1;						   // NO: we set a default to display first page 
  }

// To output a page from the list array we define page start and end based on user page number
// This section is not required for the NAV bar but may be of use when outputing pages 
//   $start = ($pageNum-1) * $perPage;		 // Defines any page's start boundary
//   if($outCount >= ($pageNum * $perPage)){   // Check to see if it is a full page
//	 $end =  ($pageNum * $perPage)-1;		// Yes: Set end to page boundary end -1 
//   }
//   else{									 // Not a full page end point is the total found
//	 $end = $outCount - 1;				   // Set end accordingly again -1 
//   }  
}
//##################################################################################################
  
//##################################################################################################
// If the list fitted a single page we can clean up and finish.
// Again included for completeness
if($singlePage){			 // Was it a single page
//	 include("footer.inc");   // YES: write footer, completes page

echo "</body>"; // replaces footer for testing
echo "</html>"; // replaces footer for testing

 exit;					// nothing else to do
}
//##################################################################################################
// The database contains multi-pages one of these pages will have been displayed either the deafult
// or one a user selected. We now construct a navigation bar allowing other pages to be selected. 
// This nav bar is dynamic and adjusts to the number of pages found. Links are added until a predefined
// maximum is reached. For example if I define a core group to have a maximum of three, links are 
// displayed in this sequence [1], [1] [2] and [1] [2][3].
// When the number of pages exceeds the core group’s capacity, additional links (I use chevrons)
// transform the core group into a variable block for example <<<[4][5][6]>>> clicking on the left
// chevrons slides the block to give <<<[1][2][3]>>>  click on the right chevrons slides the block
// to produce <<<[7][8][9]>>> .
// When the number of pages exceeds three blocks, I hammer in fixed reference points. These are the
// first and last page links added to either side of the chevrons; again automatically added
// only when required. It is more difficult to explain than implement. 
//==================================================================================================

$self = $_SERVER['PHP_SELF']; // This page's path used in link creation
$numNavItems = 5;			 // Number of seperate links to display in nav bar menu
						   // ie number of links in core group
//### Dynamic nav bar creation. Setup 
// The nav bar is contained in a paragraph tag. We add to this string to build a complete nav bar.
$gbListNav = "<p  class='mpgozbnav' >";		   // start of nav bar optional style class  

$numNavGroup = (INT)(($pageNum-1)/$numNavItems); // Calculate number of navigation groups
											   // multiples of nav items (sliding blocks)

if($numberOfPages > (($numNavGroup+1)*$numNavItems)){ // More than a full block of nav links required 
 $ref = ($numNavGroup+1)*$numNavItems;				// Yes: calculate pages catered for within
}													 // a full group of links.
else{					   // No: could be equal or less than a full group of links 
  $ref = $numberOfPages;	// hence all the pages are catered for.
}
		  
//Show page 1 link, back ref (chevrons) to previous page 
$back_ref	= $numNavGroup*$numNavItems;		 // back navigation  
$forward_ref = (($numNavGroup+1)*$numNavItems)+1; // forward navigation  

if($numNavGroup >0){ // Add first page and back nav (chevrons)to menu 
$gbListNav .= "<a href=\"$self?page=1\">Page1 </a> ";				// link
$gbListNav .= "<a href=\"$self?page=$back_ref\"><<< </a>";  // chevrons
}

// Add page nav core group and square brackets or other separator. 
for($page = $numNavGroup*$numNavItems+1; $page < $ref+1; $page++){
$gbListNav .=  "[<a href=\"$self?page=$page\">$page</a>]";
}

 if($numberOfPages >(($numNavGroup+1)*$numNavItems) ){ // Add last page and forward nav
$gbListNav .=  "<a href=\"$self?page=$forward_ref\">>&gt></a> "; //chevrons
$gbListNav .= "<a href=\"$self?page=$numberOfPages\">Page $numberOfPages</a> ";
 }

 $gbListNav .= "</P><br class='mpozbr'>"; // complete the paragraph
 echo $gbListNav;	 // after all that hard work display it
//######################################## END #####################################################

?>
</body>
</html>

 

Well have fun :)

 

PS this site is worth a visit http://www.digioz.com/phpscripts.php

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...