Jump to content

paganation help please..


techker

Recommended Posts

hey guys i have this script i found it works in all but it does not link to page 2?it shows like 10 results on 2 pages bu the second page is not there?

 

<? //---------------------------------------------------------------------------------------
////////////////////////////////////////////
//  PAGINATION FUNCTION  //
//  by: Karl Steltenpohl          //
////////////////////////////////////////////
$con = mysql_connect("localhost","t","k"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("techker_softcore", $con);



function pagination($table, $order, $searchstring, $pre, $pos, $nav, $page, $pages)
{
///////////////////////
//  Get Current Url  //
///////////////////////
$webpage = basename($_SERVER['PHP_SELF']);
global $webpage;

////////////////////////
//  Sorter and Pagination Query Begin  //
/////////////////////////////////////////
//$pre = $_REQUEST['pre'];
//$pos = $_REQUEST['pos'];
//$nav = $_REQUEST['nav'];
//$page = $_REQUEST['page'];
//$pages = $_REQUEST['pages'];


///////////////////////////////////////////
//  Set Initial Pre Pos and Page Limits  //
///////////////////////////////////////////
if($pre == "" and $pos == "" and $page == "")
{
$pre = 0;
$pos = 9;
$page = 1;
}


///////////////////////////////
//  User Navigates Previous  //
///////////////////////////////
if($nav == "prev")
{
$pre = ($pre - 10);
$pos = ($pos - 10);
$page = ($page - 1);
}


///////////////////////////
//  User Navigates Next  //
///////////////////////////
if($nav == "next")
{
$pre = ($pre + 10);
$pos = ($pos + 10);
$page = ($page + 1);
}


/////////////////////////////
//  If page number to low  //
/////////////////////////////
if($page < 1)
{
$pre = 0;
$pos = 9;
$page = 1;
}

//////////////////////////////
//  If page number to high  //
//////////////////////////////
if($page > $pages)
{
$pre = 0;
$pos = 9;
$page = 1;
}


//////////////////////////////////////////
//  Select for total number or results  //
//////////////////////////////////////////
$r = "SELECT DISTINCT * FROM $table $searchstring";
$re = mysql_query($r) or die("error 12547");
$nums = mysql_num_rows($re);


////////////////////////////////////////////
//  Select for current displayed results  //
////////////////////////////////////////////
$request = "SELECT DISTINCT * FROM $table $searchstring ORDER BY $order DESC LIMIT $pre, 10";
$result = mysql_query($request) or die("error 25352");
$num = mysql_num_rows($result);


///////////////////////////////////////
//  Determine total number of pages  //
///////////////////////////////////////
$pages = ceil($nums/10);


/////////////////////////////////
//  Create Navigation Display  //
///////////////////////////////// 
$navigation = "
$nums entries on $pages Page(s)<br>
<a href=\"$webpage?page=$page&nav=prev&pre=$pre&pos=$pos&pages=$pages&view=view\">Previous</a> |
Page $page |
<a href=\"$webpage?page=$page&nav=next&pre=$pre&pos=$pos&pages=$pages&view=view\">Next</a><br>
Results $pre - $pos
";

/////////////////////////////////
//  Create Paginagtion Array   //
/////////////////////////////////
// result is the result of the limited query
$pagination = array($navigation, $result, $num);


/////////////////////////////////
//  Return Paginagtion Array   //
/////////////////////////////////
return $pagination;
}//end function



//--------------------------------------------------------------------------------------------
//Here is an example of how to impliment it
//------------------------------------------------------------------------------------------

//this is the search string to the sql db
$searchstring = "WHERE `type` = 'sketch'";

//this is the table being searched
$table = "softcore";

//this is the table field to order the results by
$order = "id";

// call the function
$pagination = pagination($table, $order, $searchstring, $pre, $pos, $nav, $page, $pages);

//this pulls out the display
$navigation = $pagination[0];

//this pulls out the results
$result = $pagination[1];

//this pulls out the num of results
$num = $pagination[2];

//echo the display onto the site
while ($row = mysql_fetch_array($result)) 
	{

	 echo '<th scope="row"><a href="/admin/art/'. $row['pic'] .'" target="_blank" >
<img src="/admin/imgsize.php?w=60&h=50&img=art/'. $row['pic'] .'" border="0" alt="" />
</a>
<th />'; 

	}
echo"<br>$navigation</br>";

//now all you need to do is loop the result based on the num
//each page will display 10 results.?>

 

link:http://softcoredesign.com/test2.php?page=1&nav=next&pre=0&pos=9&pages=2&view=view

Link to comment
Share on other sites

<?php

$page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page'];
$page = ceil($page);
$limit = 10;

$start = $limit;
$end = $page*$limit-($limit);

$amount_check = "SELECT `message` FROM `forum_replies` WHERE `tid`='".$id."'";
$amount_check_res = mysql_query($amount_check) or die(mysql_error());
$amount_count = mysql_num_rows($amount_check_res);
$pages = ceil($amount_count/$limit);

$previous = ($page-1 <= 0) ? "« Prev" : "<a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>";
$nextpage = ($page+1 > $pages) ? " Next »" : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>";

echo $previous;
for($i=1;$i<=$pages;$i++){
$href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".$i."\">".$i."</a> ";
   
echo $href;
}
echo $nextpage;

$select_sql = "SELECT * FROM `forum_replies` WHERE `tid` = ".$id." ORDER BY `id` ASC LIMIT ".$end.", ".$start."";
$select_res = mysql_query($select_sql) or die(mysql_error()); 

?>

 

here is the code i watched a tutorial for. take a look and see what you can find out.

Link to comment
Share on other sites

ill try to combine the two together.

 

What results do you want the page to show?

 

edit: try this

 

<?php 

$con = mysql_connect("localhost","t","k"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("techker_softcore", $con);

function pagination($table, $order, $searchstring, $pre, $pos, $nav, $page, $pages)
{
$webpage = basename($_SERVER['PHP_SELF']);
global $webpage;

$pre = $_REQUEST['pre'];
$pos = $_REQUEST['pos'];
$nav = $_REQUEST['nav'];
$page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page'];
$page = ceil($page);
$limit = 10;

$start = $limit;
$end = $page*$limit-($limit);

$amount_check = "SELECT DISTINCT FROM $table $searchstring";
$amount_check_res = mysql_query($amount_check) or die(mysql_error());
$amount_count = mysql_num_rows($amount_check_res);
$pages = ceil($amount_count/$limit);

$request = "SELECT DISTINCT * FROM $table $searchstring ORDER BY $order DESC LIMIT $pre, 10";
$result = mysql_query($request) or die("error 25352");
$num = mysql_num_rows($result);

if($pre == "" and $pos == "" and $page == "")
{
	$pre = 0;
	$pos = 9;
	$page = 1;
}

if($nav == "prev")
{
	$pre = ($pre - 10);
	$pos = ($pos - 10);
	$page = ($page - 1);
}

if($nav == "next")
{
	$pre = ($pre + 10);
	$pos = ($pos + 10);
	$page = ($page + 1);
}

if($page < 1)
{
	$pre = 0;
	$pos = 9;
	$page = 1;
}

if($page > $pages)
{
	$pre = 0;
	$pos = 9;
	$page = 1;
}


$navigation = "
$nums entries on $pages Page(s)<br>
<a href=\"$webpage?page=$page&nav=prev&pre=$pre&pos=$pos&pages=$pages&view=view\">Previous</a> |
Page $page |
<a href=\"$webpage?page=$page&nav=next&pre=$pre&pos=$pos&pages=$pages&view=view\">Next</a><br>
Results $pre - $pos";

$pagination = array($navigation, $result, $num);

return $pagination;
}//end function



//--------------------------------------------------------------------------------------------
//Here is an example of how to impliment it
//------------------------------------------------------------------------------------------

//this is the search string to the sql db
$searchstring = "WHERE `type` = 'sketch'";

//this is the table being searched
$table = "softcore";

//this is the table field to order the results by
$order = "id";

// call the function
$pagination = pagination($table, $order, $searchstring, $pre, $pos, $nav, $page, $pages);

//this pulls out the display
$navigation = $pagination[0];

//this pulls out the results
$result = $pagination[1];

//this pulls out the num of results
$num = $pagination[2];

//echo the display onto the site
while ($row = mysql_fetch_array($result)) 
	{

	 echo '<th scope="row"><a href="/admin/art/'. $row['pic'] .'" target="_blank" >
<img src="/admin/imgsize.php?w=60&h=50&img=art/'. $row['pic'] .'" border="0" alt="" />
</a>
<th />'; 

	}
echo"<br>$navigation</br>";

//now all you need to do is loop the result based on the num
//each page will display 10 results.?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

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