0

Hello Friends,

i am having problem in pagination of my php website

i written the code like this its working for first page good

from second page onwards it showing all the results in a single page

<?php if((!defined('BASEPATH'))) exit('No direct script access allowed');?>
<!-- HEADER -->
<? $this->load->includes('header');?>
<!-- HEADER -->

<table width="100%" height="931" border="0" cellpadding="0" cellspacing="0" background="images/middlebackground.gif">
  <tr>
    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><table width="995" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="382"></td>
            <td width="613"></td>
          </tr>
          <tr>
            <td width="382" align="center" valign="top">
				<table width="378" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td align="left" valign="top"></td>
					</tr>

					<tr>
						<td height="20" align="center" valign="top">
						<!-- SEARCH -->
						<? $this->load->includes('search2');?>
						<!-- SEARCH -->
						</td>
					</tr>

					<tr>
						<td align="left" valign="top"></td>
					</tr>

					<tr>
						<td align="left" valign="top">&nbsp;</td>
					</tr>

					<tr>
						<td align="left" valign="top">&nbsp;</td>
					</tr>
				</table>
				
				<!-- LEFT BANNERS -->
				<? $this->load->includes('left_banners4');?>
				<!-- LEFT BANNERS -->
			  
			</td>
			<td width="613" align="left" valign="top">
				<table width="613" border="0" align="center" cellpadding="0" cellspacing="0">

				<!-- TOP BANNER -->
				<? $this->load->includes('top_banner');?>
				<!-- TOP BANNER -->				

				<tr>
				  <td height="20" align="left" valign="top">&nbsp;</td>
				  <td height="20" align="left" valign="top">
                  <!--<img src="images/banner.gif" width="559" height="208" />-->
                 
          <? $this->load->includes('slide');?>
                  </td>
				  <td height="20" align="left" valign="top">&nbsp;</td>
				  </tr>
				<tr>
					<td height="20" align="left" valign="top">&nbsp;</td>
					<td height="20" align="left" valign="top">&nbsp;</td>
					<td height="20" align="left" valign="top">&nbsp;</td>
				</tr>

				<tr>
					<td height="20" align="left" valign="top"></td>
					<td height="25" align="left" bgcolor="#04A5C1"><span class="style14">&nbsp;&nbsp;Featured Hotels And Resorts.</span></td>
					<td height="20" align="left" valign="top"></td>
				</tr>

				<tr>
					<td height="20" align="left" valign="top"></td>
					<td height="20" align="left" valign="top">&nbsp;</td>
					<td height="20" align="left" valign="top"></td>
				</tr>

				<?
				$page_name="?index6"; //  If you use this code with a different page ( or file ) name then change this 
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}
$eu = ($start - 0);                
$limit = 5;                                 // No of records to be shown per page.
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 				
$COND .= " hotel_id <> 0 AND is_futured='Y'  AND status=1 order by hotel_name limit $eu,$limit";
//$qur="select * from tz_hotels $COND order by hotel_id desc limit $eu,$limit";
//$res1=mysql_query($qur);
//$nume=mysql_num_rows($qur);
				//$COND .= " hotel_id <> 0 AND is_futured='Y'  AND status=1 order by hotel_name";
				$this->res = $this->db->select(Array('hotels'),Array("hotel_id,hotel_name,is_futured,hotel_desc"),$COND);
				$this->TCN = $this->db->row_count('hotels',$COND);
				print_r($this->TCN);
				?>
				
				<!-- HOTEL -->
				<tr>
					<td height="20" align="left" valign="top"></td>
					<td height="20" align="left" valign="top">
                    
						<table width="559" border="0" align="center" cellpadding="0" cellspacing="0">
                        <? 
						while($row = $this->db->fetch_object($this->res)){
						?>
							<tr>
							<td width="469" height="25" class="main3" >
								<span class="main1">
								<A HREF=""><?=$this->strings->strip_slashes($row->hotel_name)?></a>								
								</span>
							</td>
							<td width="90" rowspan="2">
							<!-- IMAGE -->
							<div align="right">
								<A HREF="">
								<img src="uploads/hotels/<?=$this->common->fnHotelImage($row->hotel_id)?>" width="84" height="71" />
								</A>
							</div>
							<!-- IMAGE -->
							</td>
						</tr>

						<tr>
							<td class="main3">
								<div align="justify">
									<span class="style27">
										<font color="#636363">
											<?=substr($this->strings->strip_slashes($row->hotel_desc),0,165)?>
										</font>
										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
									</span>
									<span class="style39">
										<A HREF="" class="readmore"><B>Read More</B></a>
									</span>
								</div>
							</td>
						</tr>
                        <? }?>

						<tr>
							<td height="15" colspan="2">
								<div align="center">
									<img src="images/line.gif" width="500" height="8" />
								</div>
							</td>
						</tr>
                        
                        <tr>
							<td height="15" colspan="2" align="center">
                            
                            <?
							//print_r($back);
							//$qur2=mysql_query("select * from tz_hotels where hotel_id<>0 AND status=1 ");
							//$nume=mysql_num_rows($qur2);
							
								if($this->TCN > $limit ){ 
								
								// Let us display bottom links if sufficient records are there for paging

/////////////// Start the bottom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='50%' botder='1'><tr><td  align='left' width='30%'>hi";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) { 
echo "ROcky";
print "<a href='$page_name?start=$back&limit=$limit'><font face='Verdana' size='2'>PREV</font></a>"; 
} 
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $this->TCN;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i&limit=$limit'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";}        /// Current page is not displayed as link and given font color red
$l=$l+1;
}print_r($this->TCN);
print_r($this1);

echo "</td><td  align='right' width='30%'>";
//print_r($this1);
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $this->TCN) { 
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td></tr></table>";
//print_r($next);


}

?>
							</td>
						</tr>
						</table>
                      <?php /*?>  </form><?php */?>
					</td>
					<td height="20" align="left" valign="top"></td>
				</tr>
				<!-- HOTEL -->				

				<?php /*?><?}}else{?><?php */?>
				<tr>
					<td height="20" align="left" valign="top"></td>
					<td height="25" align="left" bgcolor="#cccccc">
					<div style="padding-top:40px;padding-bottom:40px;" align="center"><FONT SIZE="" COLOR="red" face="vardana">Hotels Is Not Available</FONT></div>
					</td>
					<td height="20" align="left" valign="top"></td>
				</tr>				

				<tr>
					<td align="left" valign="top" colspan="3">&nbsp;</td>
				</tr>

			<?php /*?>	<?}?><?php */?>

				<tr>
					<td height="20" align="left" valign="top"></td>
					<td height="20" align="left" valign="top" class="main3"><img src="images/add1.gif" width="412" height="54" /></td>
					<td height="20" align="left" valign="top"></td>
				</tr>
				<tr>
					<td colspan="3" align="left" valign="top">
						<table width="602" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td align="left" valign="top">&nbsp;</td>
							</tr>
						</table>
					</td>
				</tr>
				</table>
			</td>
          </tr>
        </table></td>
        </tr>
        </table></td>
  </tr>
</table>
<!-- FOOTER -->
<? $this->load->includes('footer');?>
<!-- FOOTER -->

so help me

Thanks in advance

Edited by nav33n: Use [code][/code] tags to wrap your code for easy readability.

2
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by rajabhaskar525
0

replace $start=$_GET;
with

$start=$_REQUEST['start'];

put echo before $COND

echo $eu,$limit;
$COND .= " hotel_id <> 0 AND is_futured='Y' AND status=1 order by hotel_name limit $eu,$limit";

see the start & limit value you will find error. i hope it helps you.

Edited by rajabhaskar525: n/a

0

Thanks for ur quick reply

but i cahnged that code and iam getting the values of $eu and $limit properly
but not getting the $start value it is showing as '0'
the main problem is with that only

please give the solution

Edited by virspy: n/a

0

intilize $start=0; in first page; do like this

if(isset($_REQUEST['start']) && ($_REQUEST['start']!=""))
{
$start=$_REQUEST['start'];
}
else
{
$start=0;
}

pass $start as querystringvariable in back and next hyperlinks.
like below

some.php?start=$start&somevariable=$some?

get this variable

$start=$_REQUEST['start'];

Edited by rajabhaskar525: n/a

0

Good Morning
and Thanks for quick reply
i changed the code as u told but it still creating problems sir
first it showing the required no of results and after that when we click on next it is not showing the results
please help me

my code is like this

<?php if((!defined('BASEPATH'))) exit('No direct script access allowed');?>
<!-- HEADER -->
<? $this->load->includes('header');?>
<!-- HEADER -->

<table width="100%" height="931" border="0" cellpadding="0" cellspacing="0" background="images/middlebackground.gif">
<tr>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><table width="995" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="382"></td>
<td width="613"></td>
</tr>
<tr>
<td width="382" align="center" valign="top">
<table width="378" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"></td>
</tr>

<tr>
<td height="20" align="center" valign="top">
<!-- SEARCH -->
<? $this->load->includes('search2');?>
<!-- SEARCH -->
</td>
</tr>

<tr>
<td align="left" valign="top"></td>
</tr>

<tr>
<td align="left" valign="top">&nbsp;</td>
</tr>

<tr>
<td align="left" valign="top">&nbsp;</td>
</tr>
</table>

<!-- LEFT BANNERS -->
<? $this->load->includes('left_banners4');?>
<!-- LEFT BANNERS -->

</td>
<td width="613" align="left" valign="top">
<table width="613" border="0" align="center" cellpadding="0" cellspacing="0">

<!-- TOP BANNER -->
<? $this->load->includes('top_banner');?>
<!-- TOP BANNER -->	

<tr>
<td height="20" align="left" valign="top">&nbsp;</td>
<td height="20" align="left" valign="top">
<!--<img src="images/banner.gif" width="559" height="208" />-->

<? $this->load->includes('slide');?>
</td>
<td height="20" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td height="20" align="left" valign="top">&nbsp;</td>
<td height="20" align="left" valign="top">&nbsp;</td>
<td height="20" align="left" valign="top">&nbsp;</td>
</tr>

<tr>
<td height="20" align="left" valign="top"></td>
<td height="25" align="left" bgcolor="#04A5C1"><span class="style14">&nbsp;&nbsp;Featured Hotels And Resorts.</span></td>
<td height="20" align="left" valign="top"></td>
</tr>

<tr>
<td height="20" align="left" valign="top"></td>
<td height="20" align="left" valign="top">&nbsp;</td>
<td height="20" align="left" valign="top"></td>
</tr>

<?
$page_name="?index4"; // If you use this code with a different page ( or file ) name then change this 
//$start=$_REQUEST['start'];
if(isset($_REQUEST['start']) && ($_REQUEST['start']!=""))
{
$start=$_REQUEST['start'];
}
else
{
$start=0;
}
//$start=$_REQUEST['start'];
print_r($srart);
$eu = ($start - 0); 
$limit = 5; // No of records to be shown per page.
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 
$COND .= " hotel_id <> 0 AND is_futured='Y' AND status=1 order by hotel_name limit $eu,$limit";
$this->res = $this->db->select(Array('hotels'),Array("hotel_id,hotel_name,is_futured,hotel_desc"),$COND);
$this->TCN = $this->db->row_count('hotels',$COND);
print_r($this->TCN);
?>

<!-- HOTEL -->
<tr>
<td height="20" align="left" valign="top"></td>
<td height="20" align="left" valign="top">

<table width="559" border="0" align="center" cellpadding="0" cellspacing="0">
<? 
while($row = $this->db->fetch_object($this->res)){
?>
<tr>
<td width="469" height="25" class="main3" >
<span class="main1">
<A HREF=""><?=$this->strings->strip_slashes($row->hotel_name)?></a>	
</span>
</td>
<td width="90" rowspan="2">
<!-- IMAGE -->
<div align="right">
<A HREF="">
<img src="uploads/hotels/<?=$this->common->fnHotelImage($row->hotel_id)?>" width="84" height="71" />
</A>
</div>
<!-- IMAGE -->
</td>
</tr>

<tr>
<td class="main3">
<div align="justify">
<span class="style27">
<font color="#636363">
<?=substr($this->strings->strip_slashes($row->hotel_desc),0,165)?>
</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</span>
<span class="style39">
<A HREF="" class="readmore"><B>Read More</B></a>
</span>
</div>
</td>
</tr>
<? }?>

<tr>
<td height="15" colspan="2">
<div align="center">
<img src="images/line.gif" width="500" height="8" />
</div>
</td>
</tr>

<tr>
<td height="15" colspan="2" align="center">

<?
if($this->TCN > $limit ){ 
echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>hi";
if($back >=0) { 
echo "ROcky";
print "<a href='$page_name?start=$back&limit=$limit'><font face='Verdana' size='2'>PREV</font></a>"; 
} 
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $this->TCN;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i&limit=$limit'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";} 
$l=$l+1;
}
echo "</td><td align='right' width='30%'>";
if($this1 < $this->TCN) { 
//print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
print "<a href='$page_name?start=$next&limit=$limit'?><font face='Verdana' size='2'>NEXT</font></a>";} 
$start=$_REQUEST['start'];
echo "</td></tr></table>";
}

?>
</td>
</tr>
</table>
<?php /*?> </form><?php */?>
</td>
<td height="20" align="left" valign="top"></td>
</tr>
<!-- HOTEL -->	

<?php /*?><?}}else{?><?php */?>
<tr>
<td height="20" align="left" valign="top"></td>
<td height="25" align="left" bgcolor="#cccccc">
<div style="padding-top:40px;padding-bottom:40px;" align="center"><FONT SIZE="" COLOR="red" face="vardana">Hotels Is Not Available</FONT></div>
</td>
<td height="20" align="left" valign="top"></td>
</tr>	

<tr>
<td align="left" valign="top" colspan="3">&nbsp;</td>
</tr>

<?php /*?>	<?}?><?php */?>

<tr>
<td height="20" align="left" valign="top"></td>
<td height="20" align="left" valign="top" class="main3"><img src="images/add1.gif" width="412" height="54" /></td>
<td height="20" align="left" valign="top"></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top">
<table width="602" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<!-- FOOTER -->
<? $this->load->includes('footer');?>
<!-- FOOTER -->

Edited by nav33n: Use [code][/code] tags to wrap your code for easy readability.

0

can explain

$page_name="?index4"

write like this

$page_name="yourfilename.php"

where do you to redirect your page. what is the $page_name
in below code.

<?
if($this->TCN > $limit ){ 
echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>hi";
if($back >=0) { 
echo "ROcky";
print "<a href='$page_name?start=$back&limit=$limit'><font face='Verdana' size='2'>PREV</font></a>"; 
} 
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $this->TCN;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i&limit=$limit'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";} 
$l=$l+1;
}
echo "</td><td align='right' width='30%'>";
if($this1 < $this->TCN) { 
//print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
print "<a href='$page_name?start=$next&limit=$limit'?><font face='Verdana' size='2'>NEXT</font></a>";} 
$start=$_REQUEST['start'];
echo "</td></tr></table>";
}

?>

page isnot goiny to next page. that why you are not getting $start value. check and fix $page_name="yourfilename.php"

Edited by rajabhaskar525: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.