Jump to content

[SOLVED] pagination html links


jaymc

Recommended Posts

Does anyone have any nice prebuilt, re-useable functions that handle creating html numbed paged links to toggle between mysql result sets

 

e.g mysql returns 500 rows, you split that up into 50 pages, 10 rows

 

Im trying to avoid ugly code each time I need to do this, would be nice to have a reusable function that can handle returning the html paged links as well as maintain query strings

 

I've seen a few on google but they arnt too great. Also the PHP_Pear is not to hot either

 

How do you experts on here go about this :)

Link to comment
https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/
Share on other sites

Ah I ended up making my own, I guess the best is one that works for you. Here it is :)

 

// ###########################################
// FUNCTION TO GENERATE DROP DOWN PAGE LINKS #
// ###########################################

function page_links($rowsPerPage, $totalRows, $currentRow, $url = false) {

// ----------------------------------
// BUILD SELECT OPTION FOR EACH PAGE 
// ----------------------------------

	if ($totalRows % $rowsPerPage == 0) {$offset = 0;} else {$offset = 1;}

	$pages = floor($totalRows / $rowsPerPage) + $offset;

	while ($i < $pages) {
		$i++;
		$page_from = ($i * $rowsPerPage) - $rowsPerPage;	
		if ($page_from == $currentRow) {$selected = " SELECTED";} else {$selected = "";}
		$page_options .= "<option value=\"$page_from\"{$selected}>Page $i</option>";
	}

// -------------------------------
// REMOVE pageFrom= FROM QUERY STRING 
// -------------------------------

	if (!$url) {$url = $_SERVER['QUERY_STRING'];}

	parse_str($url, $queryString);
	unset($queryString['rowFrom']);
	$urlQuery = rawurldecode(http_build_query($queryString));

// --------------------------------------
// PUT THE DROP DOWN TOGETHER AND RETURN 
// --------------------------------------

	$page_jump = "<SELECT style=\"width:80px\" id=\"quick_jump_menu\" OnChange=\"ajaxopen('#center_content', '$_SERVER[sCRIPT_NAME]?$urlQuery&rowFrom=' + this.value)\">$page_options</SELECT>";

	return $page_jump;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.