Jump to content


Photo

php?page=0


  • Please log in to reply
19 replies to this topic

#1 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 08 February 2007 - 01:42 PM

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

#2 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 08 February 2007 - 09:12 PM

any help ?
IPB Image

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

IPB Image

#3 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 11 February 2007 - 12:22 AM

lol... i dont see anything wrong... i had a script that did what you were trying to do.. but my pc is down... :)

#4 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 11 February 2007 - 11:12 AM

the Pagination aint working the bottom of 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

#5 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 11 February 2007 - 02:40 PM

What do you mean, its not showing the 1, 2, 3, ....

#6 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 11 February 2007 - 09:50 PM

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

#7 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 12 February 2007 - 10:59 AM

Where is it?

#8 kalpz

kalpz

    Beta Team Member

  • Beta Tester
  • PipPip
  • 132 posts
  • Location:New Zealand
  • IRC Nickname: LifeSteala
  • Main OS: Windows Vista

Posted 12 February 2007 - 07:30 PM

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/

#9 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 13 February 2007 - 01:41 AM

where @ in the code ? & where is what ?
IPB Image

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

IPB Image

#10 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 13 February 2007 - 01:01 PM

The recent code...? You did say "....here is the code"

#11 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 13 February 2007 - 01:05 PM

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>&nbsp;\n"; 
	} 
	for($i=1; $i <= $totalpage; $i++) { 
		if ($i == $page) { 
			echo "<b>[$i]&nbsp;</b>\n"; 
		} else { 
			echo "<a href=\"$_SERVER[PHP_SELF]?index=".$i."\">[$i]</a>&nbsp;\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

#12 kalpz

kalpz

    Beta Team Member

  • Beta Tester
  • PipPip
  • 132 posts
  • Location:New Zealand
  • IRC Nickname: LifeSteala
  • Main OS: Windows Vista

Posted 13 February 2007 - 03:21 PM

Are you getting data from a database?
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/

#13 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 14 February 2007 - 01:15 AM

no i do not use a database suppose to work without one
IPB Image

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

IPB Image

#14 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 14 February 2007 - 01:50 AM

But do you get anything?

#15 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 14 February 2007 - 05:09 AM

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

#16 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 14 February 2007 - 11:33 AM

Change the $max to 9 or 10.

#17 Ric

Ric

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 1,535 posts
  • Gender:Male
  • Location:Cambridge,UK
  • Interests:Electronics
    Internet in general
    Open source projects
  • SourceForge IDmpgcan
  • Wiki ID: Ric
  • Main OS: Windows XP

Posted 14 February 2007 - 06:59 PM

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>&nbsp;\n"; 
	}
	else{ // display links in block
	echo "<a href=\"$_SERVER[PHP_SELF]?index=".$i."\">[$i]</a>&nbsp;\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 :)

#18 override

override

    Beta Team Member

  • Beta Tester
  • Pip
  • 36 posts

Posted 14 February 2007 - 07:46 PM

TY TY TY that is what i am looking for TY TY TY Ric
IPB Image

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

IPB Image

#19 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 15 February 2007 - 12:19 AM

:) Thats Ric....

#20 Ric

Ric

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 1,535 posts
  • Gender:Male
  • Location:Cambridge,UK
  • Interests:Electronics
    Internet in general
    Open source projects
  • SourceForge IDmpgcan
  • Wiki ID: Ric
  • Main OS: Windows XP

Posted 15 February 2007 - 04:05 PM

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&nbsp;</a> ";				// link
	$gbListNav .= "<a href=\"$self?page=$back_ref\">&lt;&lt;&lt;&nbsp;</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;&gt&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




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users