page numbering reference

A

Anonymous

Guest
HI guys,

I am trying to do page numbering for my results page. At the moment, everything works fine but I wish to create a page reference in my results page.

For your information, i can see all the pages avaiable(i set the query limit to 10 results per page) at the bottom of my page. The problem is, it doesn't show me which page i am viewing. When i press page 3, the page 3 still an active hyperlink shown at the bottom.

I am wondering is there anyway i make amend the code so i know which page i am viewing instead of guessing which page i am viewing ?

Please advise.

my code:
if ($Total > 0)
{
if ($Result_Set<$Total && $Result_Set>0)
{
$Res1 = $Result_Set - $Per_Page;
echo "<a href=\"".$_SERVER['PHP_SELF']."?$page_no=$c&Result_Set=$Res1&c_category=".$_REQUEST['c_category']."&c_country=".$_REQUEST['c_country']."&c_state=".$_REQUEST['c_state']."&c_desc=".$_REQUEST['c_desc']."&c_name=".$_REQUEST['c_name']."\"><b><< Previouse Page </b></a>";
}
//calculate and display page #links
$Pages = $Total / $Per_Page;
if ($Pages>1)
{
for ($b=0,$c=1; $b< $Pages; $b++, $c++)
{
$Res1=$Per_Page * $b;
echo "<a href=\"".$_SERVER['PHP_SELF']."?$page_no=$c&Result_Set=$Res1&c_category=".$_REQUEST['c_category']."&c_country=".$_REQUEST['c_country']."&c_state=".$_REQUEST['c_state']."&c_desc=".$_REQUEST['c_desc']."&c_name=".$_REQUEST['c_name']."\"><b>$c</b></a>\n";
}
}

if ($Result_Set>=0 && $Result_Set<$Total)
{
$Res1=$Result_Set+$Per_Page;
if($Res1<$Total)
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?$page_no=$c&Result_Set=$Res1&c_category=".$_REQUEST['c_category']."&c_country=".$_REQUEST['c_country']."&c_state=".$_REQUEST['c_state']."&c_desc=".$_REQUEST['c_desc']."&c_name=".$_REQUEST['c_name']."\"><b>Next Page >></b></a>";
}
}
}
 
You would do something like

Code:
if($_REQUEST['page_no'] == $c)
{
  echo $c
}
else
{
   //echo the link like you have been
}

you could also use a tirnary statement.
 
You are calling $c before and after the for loop that defines and uses it. You need another outside variable that keeps track of your page. Then when you hit previous and next it will still be able to tell which page you are referring to by $currnet_page + or - 1.

here is your code which I added to to make it funtion like you asked.
Code:
<?php
$page_no = "page_num";
$current_page = ($_REQUEST[page_num]) ? $_REQUEST[page_num] : 1;
$next_page = $current_page + 1;
$previous_page = $current_page -1;
$Total = "50";
$Per_Page = "15";
$Result_Set = $_REQUEST[Result_Set];
$_REQUEST[c_category] = "Category" ;
$_REQUEST[c_country] = "Country";
$_REQUEST[c_state] = "State";
$_REQUEST[c_desc] = "Description";
$_REQUEST[c_name] = "Name";
?>
<HTML><TITLE>:: DISPLAYING ENTRIES :: PAGE NUMBER <?php print $page_num ?> ::</TITLE>
<BODY BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0">
<FONT SIZE="1" FACE="Georgia">
<P>
<TABLE BORDER="0" WIDTH="100%">
<TR>
<TD WIDTH="100%" ALIGN="CENTER">

<TABLE BORDER="1" BORDERCOLOR="#000000" WIDTH="95%" CELLPADDING="5" CELLSPACING="0">
<TR><TD WIDTH="100%" ALIGN="CENTER" VALIGN="MIDDLE">
<?php
if ($Total > 0) { 
	if ($Result_Set<$Total && $Result_Set>0) { 
		$Res1 = $Result_Set - $Per_Page; 
		echo "<a 

href=\"".$_SERVER['PHP_SELF']."?$page_no=$previous_page&Result_Set=$Res1&c_category=".$_REQUEST['c_category']."&c_country".$_REQUEST['c_cou

ntry']."&c_state=".$_REQUEST['c_state']."&c_desc=".$_REQUEST['c_desc']."&c_name=".$_REQUEST['c_name']."\"><b><< Previous Page </b></a>&nbsp"; 
	} else {echo "<b><< Previous Page</b>"; }
//calculate and display page #links 
$Pages = $Total / $Per_Page; 
if ($Pages>1) { 
	for ($b=0,$c=1; $b< $Pages; $b++, $c++) { 
		$Res1=$Per_Page * $b; 
		echo "<a 

href=\"".$_SERVER['PHP_SELF']."?$page_no=$c&Result_Set=$Res1&c_category=".$_REQUEST['c_category']."&c_country=".$_REQUEST['c_country']."&c_st

ate=".$_REQUEST['c_state']."&c_desc=".$_REQUEST['c_desc']."&c_name=".$_REQUEST['c_name']."\"><b>$c</b></a>\n"; 
	} 

} 

	if ($Result_Set>=0 && $Result_Set<$Total) { 
		$Res1=$Result_Set+$Per_Page; 
		if($Res1<$Total) { 
			echo "&nbsp<a 

href=\"".$_SERVER['PHP_SELF']."?$page_no=$next_page&Result_Set=$Res1&c_category=".$_REQUEST['c_category']."&c_country=".$_REQUEST['c_countr

y']."&c_state=".$_REQUEST['c_state']."&c_desc=".$_REQUEST['c_desc']."&c_name=".$_REQUEST['c_name']."\"><b>Next Page >></b></a>"; 
		}  else { echo "<b>Next Page >></b>"; }
	} 
}
?>
</TD>
</TR>
<TR>
<TD WIDTH="100%" HEIGHT="100%" ALIGN="CENTER" VALIGN="MIDDLE">
<?php
print "Current Page: ";
print $current_page;
?>
</TABLE>

</TD></TR>
</TABLE>
</FONT>
</BODY>
</HTML>

I had to add the _REQUEST vars and some others so I could work with it stand alone, but you should get the picture.
 
Back
Top