Hi all, i have this program for limiting the list of records in a single page,,,,,,,but how to incorporate this in my program.......i am unable to understand it..........what is test.php.......can any one explain me pls........in my program i am just displaying n number of items......i got this program, from some one.....but dont know how to proceed.

<?php
session_start();
include("pagenavigation.php");
include("header.php") ;
$totalResults = 20;
$resultsPerPage = 5;
$page = $_GET[page];
$startHTML = "<b>Showing Page {page} of {pages}</b>: Go to Page ";
$appendSearch = "&a=1&b=2";
$range = 5;
$link_on = "<a href='test.php?page={num}{appendSearch}'><b>{num}</b></a>";
$link_off = "<a href='test.php?page={num}{appendSearch}'>{num}</a>";
$back = " <a href='test.php?page=1{appendSearch}'><<</a> ";
$forward = " <a href='test.php?page={pages}{appendSearch}'>>></a> ";
$myNavigation = New PageNavigation($totalResults, $resultsPerPage, $page, $startHTML, $appendSearch, $range, $link_on, $link_off, $back, $forward);
 echo $myNavigation->getHTML();
?>
<?php
class PageNavigation {
 /* Global Variables */
var $totalResults; 
var $resultsPerPage; 
var $page; 
var $pages; 
var $startHTML; 
var $appendSearch; 
var $range; 
var $link_on; 
var $link_off; 
var $back; 
var $forward; 
var $product; 

/****************************************
* Constructor *
*****************************************/

function PageNavigation($totalResults, $resultsPerPage, $page, $startHTML, $appendSearch, $range, $link_on, $link_off, $back, $forward) {
 $this->totalResults = $totalResults;
$this->resultsPerPage = $totalResults;
$this->page = $page;
$this->pages = ceil($totalResults / $resultsPerPage);
$this->product = $startHTML;
$this->appendSearch = $appendSearch;
$this->range = $range;
$this->link_on = $link_on;
$this->link_off = $link_off;
$this->back = $back;
$this->forward = $forward;
}

/****************************************
* Replace Alias *
*****************************************/

function replace_alias() {
$this->product = str_replace("{page}", $this->page, $this->product);
$this->product = str_replace("{pages}", $this->pages, $this->product);
$this->product = str_replace("{appendSearch}", $this->appendSearch, $this->product);
}

/****************************************
* GET HTML *
*****************************************/

function getHTML() 
{
$pageLinks = array();
 //loop array of needed pages
for ($i=0;$i<$this->pages;$i++) 
	{
		$num = $i+1;
		$showNum = false;
		if ($this->page >= $num && $this->page - $this->range <= $num)
		$showNum = true;
		if ($this->page <= $num && $this->page + $this->range >= $num)
		$showNum = true;
		if ($showNum == true)
		{
			if (($num) == $this->page) 
				{
					array_push($pageLinks, str_replace("{num}", $num, $this->link_on));
				}
			else 
				{
					array_push($pageLinks, str_replace("{num}", $num, $this->link_off));
				}
		}
	}

if (($this->page - $this->range) > 1)
$this->product .= $this->back;
if (($this->page + $this->range) < $this->pages)
$this->product .= $this->forward;
$this->replace_alias();

}

}

Recommended Answers

All 4 Replies

Hi,

Provide your code and I will convert it into pagination

Hi here is my actual code...........

<? 
session_start();

	include("header.php") 







?>	 

<table width="960" border="0" cellpadding="0" cellspacing="0" align="center">
 <tr>
	   <td width="100%"><? include("top_banner.php") ?></td>			     
 </tr>
 <tr>
		<td align="center" height="48" width="100%"><? include("horizental_menu.php") ?></td>
 </tr>

<table align="center" cellpadding="0" cellspacing="0" width="100%" border="0" class="whitesite" >
						<!-- header -->
<tr><td>		
	<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr><td background="images/button_bot.jpg" width="100%" height="5" colspan="3"></td></tr>
</table>
</td></tr>

						<!-- content -->
<tr><td width="100%">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<td width="5">&nbsp;</td>
<td width="207" valign="top" class="" align="center">
						<!-- left-table -->
<table cellpadding="0" cellspacing="0" width="207" border="0" align="center">

<tr >

						     <td alt="" class="headtitle1" background="images/leftnav_title.gif" height="31" width="100%">Responses <span class="mandi">what is this?</span> </td>
							 
							 </tr>

				          <tr>
						     <td align="center" background="images/leftnav_bg.gif" width="100%">
							   <table align="center" border="0" cellpadding="1" cellspacing="0" width="190">
						         <tbody>
								   <tr>
								      <td height="1"></td></tr>
									  							 <tr><td>&nbsp;</td></tr>

						           <tr>
								       <td width="15"></td>
							           <td width="175"><a href="contractor_mail_action_contents.php" title="Personal Info" class="leftnav"><u><b>Mailbox</b></u></a></td>
						           </tr>
								   
						           <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="contractor_mail_action_contents.php" title="Change Password" class="leftnav">Inbox( )</a></td>
						           </tr>
						           
						           <tr>
								       <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
						               <td><a title="Logout" href="contractor_sent_itmes.php" class="leftnav">Sent</a></td>
								   </tr>
								    <tr>
								       <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
						               <td><a title="Logout" href="workinprogress.php" class="leftnav">Trash</a></td>
								   </tr>
								   <tr>
								       <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
						               <td><a title="Logout" href="lagoutcu.php" class="leftnav">Logout</a></td>
								   </tr>
									   <tr><td>&nbsp;</td></tr>
								   <tr>
									    <td style="background-repeat: repeat-x;" colspan="3" align="center" background="images/dot.jpg" height="1" width="200"></td></tr>
																	 <tr><td>&nbsp;</td></tr>

									 <tr>
								       <td width="15"></td>
							           <td width="175"><a href="workinprogress.php" title="Personal Info" class="leftnav"><b><u>Account Settings</u></b></a></td>
						           </tr>

										 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="workinprogress.php" title="Change Password" class="leftnav">Additional Info</a></td>
						           </tr>

										 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="workinprogress.php" title="Change Password" class="leftnav">Address Change request</a></td>
		   				           </tr>
										 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="contractor_changepassword.php" title="Change Password" class="leftnav">Change Password</a></td>
									    </tr>
										 <tr><td>&nbsp;</td></tr>
									<tr>
									    <td style="background-repeat: repeat-x;" colspan="3" align="center" background="images/dot.jpg" height="1" width="200"></td></tr>
									 <tr>
																 <tr><td>&nbsp;</td></tr>

									   
									<tr>
								       <td width="15"></td>
							           <td width="175"><a href="workinprogress.php" title="Personal Info" class="leftnav"><b><u>Response Summary</b></a></td>
						           </tr>

									 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="workinprogress.php" title="Change Password" class="leftnav">Requests recieved</a></td>
						           </tr>

										 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="workinprogress.php" title="Change Password" class="leftnav">Response sent</a></td>
		   				           </tr>
										 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="workinprogress.php" title="Change Password" class="leftnav">Activity summary</a></td>
						           </tr>
										 <tr>
							           <td><img src="images/buldot.gif" alt="" height="6" width="6"></td>
							           <td><a href="workinprogress.php" title="Change Password" class="leftnav">Conversion factor</a></td>
						           </tr>
								   							 <tr><td>&nbsp;</td></tr>
															 <tr><td>&nbsp;</td></tr>
															 <tr><td>&nbsp;</td></tr>
															 <tr><td>&nbsp;</td></tr>

	

</tbody>
						       </table>
							 </td>
						  </tr>
				          <tr>
						         <td><img src="images/leftnav_bot.gif" alt="" height="7" width="207"></td>

						  </tr>

</table>
</td>
<td width="5">&nbsp;</td>
					<!--  -->
<td valign="top">
				<!--inbox table  -->

<table cellpadding="0" cellspacing="0" width="100%" border="0" height="50%">
<tr><td height="5"></td></tr>
<tr>
<td width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td><img src="images/box_left.gif" width="10" height="31" alt=""></td>
<td nowrap  background="images/box_topbg.gif" width="100%" height="31">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<td style="padding-left:5px;" class="headtitle">Account Summary</td>
<td align="right" colspan="3" > Welcome</td>
</tr>
 </table>
<td><img src="images/box_right.gif" width="10" height="31" alt=""></td>
</tr>
<tr>
<td background="images/box_leftbg.gif" width="10"></td>
<td bgcolor="#FFFFFF">

<table  class="form-noindent" cellpadding="0" cellspacing="0" width="100%" border="0">
												
																								
												<tr>
												<td  >
												
												<span style="color:005D95"><strong> Current folder:Inbox</strong></span></td></tr>
												<tr><td align="right" colspan="3" style="color:red"> <span class="error_text"></span>  <span class="mandi"></span></td></tr>
												<tr><td height="15"></td></tr>
												<form name='form2' method='post' action="contractor.php" onsubmit="return comparision(this);" > 
												<!-- <form name='form1' method='post' action="">-->
													<tr><td>
														<table border="0" cellpadding="1"  cellspacing="5" align="center" width="100%" style="border:1px solid #EDEDED;background-color:#f6f6f6">
															
												<tr><td>
												<table   border="0" width="100%"><tr>
												<td width="5%"></td>

			<td><b><font size="3"><span style="color:005D95">From</span></b></td>
			<td><b><font size="3"><span style="color:005D95">Subject</span></b></td>
			<td><b><font size="3"><span style="color:005D95">Date</span></b></td>
			</tr>


<?php
session_start();

	include('database.php');
$result = mysql_query("SELECT * FROM  autoalto_mail" );
	
while($row = mysql_fetch_array($result))
		{
		?>
		
			
			<tr>				
					<td width="5%"></td>
					<td>
				     <? echo $row['From_user'];
						//$from_u=$row['From_user'];	
						//session_register("from_u");
			
			?></td>
					<td >
				     <a href="contractor_mail_action_contents.php?mail_id=<? echo $row['mail_id'];			 
						?>">
		
					    <?echo $row['subject'];
							$subj=$row['subject'];	
						session_register("subj");
						
						?>
					 </a>
					</td>
					<td><?echo $row['date']?></td>
				
			</tr>
				
			<tr>
				<td width="5%"></td>			
				<td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300">
				</td>
			</tr>
									
		<?		
	    }
					
	     mysql_close();
        ?>
</tr>
	</table>
</td>

</tr>
<tr><td>&nbsp;</td></tr>
<tr>

<td>
<table border="0" cellpadding="0" cellspacing="0" align="center" width="100%" style="border:1px solid #EDEDED;background-color:#f6f6f6">
<tr>
<td width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center" >
<tr>
<td><img src="images/box_left.gif" width="10" height="31" alt=""></td>
<td nowrap  background="images/box_topbg.gif" width="100%" height="31">
<table cellpadding="0" cellspacing="0" width="100%" border="0" >
<tr>
<td style="padding-left:5px;" class="headtitle">Mail Preview</td>
<td align="right" colspan="3" style="color:red"> <a href="contractor_mail_quotation.php">Open in new window</a></td>

</tr>
 </table>
<td><img src="images/box_right.gif" width="10" height="31" alt=""></td>
</tr>
<tr>
<td background="images/box_leftbg.gif" width="10"></td>
</tr>
 </table></td></tr>
<tr><td>
<table border="0" cellpadding="0" cellspacing="0" align="center" width="100%"  style="border:1px solid #EDEDED;background-color:#ffffff">

			<tr><td><b>Subject:

<? 
session_start();
	include('database.php');
	$mailid1 = $_GET['mail_id']; 
	
	session_register("mailid1");
	 $query1="SELECT * FROM  autoalto_mail where mail_id='".$mailid1."'";
	$result = mysql_query( $query1 );
	while($row = mysql_fetch_array($result))
			{ ?>
			<?
			 echo $row['subject'];
			}
mysql_close();

 ?>


</b></td>

					

<td align="right" colspan="3" style="padding-left:5px;" class="headtitle"> <a href="Contractor_reply.php"><b>Reply</b></a><span >/</span><a href="lll.html"><b>Delete</b></a><span>/</span><a href="lll.html"><b>Next</b></a></td></tr>
			<tr><td><b>From:

<? 
session_start();
	include('database.php');
	$mailid1 = $_GET['mail_id']; 
	 $query1="SELECT * FROM  autoalto_mail where mail_id='".$mailid1."'";
	$result = mysql_query( $query1 );
	while($row = mysql_fetch_array($result))
			{ ?>
			<?
			 echo $row['From_user'];
			}
mysql_close();

 ?>										
</b></td></tr>
</table>
</td></tr>
	<tr> <td >


<? 
session_start();
	include('database.php');
	$mailid1 = $_GET['mail_id']; 
//$mailid1 = $_SESSION['mailid'];
 //echo $mailid1;
 $query1="SELECT * FROM  autoalto_mail where mail_id='".$mailid1."'";

//echo $query1;
$result = mysql_query( $query1 );
//echo mysql_num_rows($result) ;
while($row = mysql_fetch_array($result))
		{ 
		 echo $row['contents'];
		}
mysql_close();

 ?>


 </td></tr>
 <tr><td>&nbsp;</td></tr>
 <tr><td>&nbsp;</td></tr>
 <tr><td>&nbsp;</td></tr>
</table>
</td>
</tr>

	
	</table>
   </td></tr>
	</form>
	</table>
	</td>
	<td background="images/box_rightbg.gif" width="10"></td>
  </tr>
  <tr>
	<td><img src="images/box_botleft.gif" width="10" height="10" alt=""></td>
	<td background="images/box_botbg.gif" width="100%" height="10" alt=""></td>
	<td><img src="images/box_botright.gif" width="10" height="10" alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<!-- right nav -->
<td width="5">&nbsp;</td>

<td width="5">&nbsp;</td>
</tr>
</table>
</td></tr>	
		<!-- footer -->
		
		
		
		<tr><td background="images/button_bot.jpg" height="7" width="100%"></td></tr>
		<tr>

		<!--    <td ><div align="center"><img src="images/vertical_line.jpg" alt="auto repair service list mechanic garage dark green line" width="940" height="8" /></div> -->
			<? include("footer.php") ?></td>
	    </tr>
      </table>
    </body>
</html>

Hi,

I think this is the code that you need to be converted. Right?

<?phpsession_start(); 	include('database.php');$result = mysql_query("SELECT * FROM  autoalto_mail" ); while($row = mysql_fetch_array($result))		{		?>  			<tr>									<td width="5%"></td>					<td>				     <? echo $row['From_user'];						//$from_u=$row['From_user'];							//session_register("from_u"); 			?></td>					<td >				     <a href="contractor_mail_action_contents.php?mail_id=<? echo $row['mail_id'];			 						?>"> 					    <?echo $row['subject'];							$subj=$row['subject'];							session_register("subj"); 						?>					 </a>					</td>					<td><?echo $row['date']?></td> 			</tr> 			<tr>				<td width="5%"></td>							<td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300">				</td>			</tr> 		<?			    } 	     mysql_close();        ?>

Yes that is the code.........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.