Web Analytics Made Easy -
StatCounter Pagenation problem - CodingForum

Announcement

Collapse
No announcement yet.

Pagenation problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pagenation problem

    Hi.. I have a pagenation problem..
    Its look fine when I first displaying the data from db.
    About 40 file will displaying in 10 pageNo
    That is correct pagenation
    The problem comes here
    When I sorting it according to the ID.
    It will display about 5 pageNo which is data for the specific ID.
    When I click (5 pageNo) the next pagenation for the ID it will display all the data (10 pages).
    Means it will display all the data from db.

    I use php5 that use boundry, controller and entity.

    Boundry (viewService.php)
    Code:
    <?php
    include('../entity/servicesEntity.php');
    ?>
    <table width="100%" border="0" cellspacing="3" cellpadding="3" class="font">
      <tr>
          
        <td class="header"><span class="text_header_side">SERVICES AND PRICE</span></td>
      </tr>
      <tr>
        <td>	
    <table width="100%" border="0" class="font">
      <tr class="text_blue">
                
              <td width="2%" nowrap>1 .</td>
    	      <td width="39%">Dry Cleaning - Gentlemean</td>
    	<td width="59%"><a href="viewServices.php?type=DCG">View</a></td>
      </tr>
      <tr class="text_blue">
                
              <td width="2%" nowrap> 2 .</td>
    	      <td width="39%">Dry Cleaning - Ladies</td>
    	<td width="59%"><a href="viewServices.php?type=DCL">View</a></td>
      </tr>
      <tr class="text_blue">
                
              <td width="2%" nowrap>3 . </td>
    	      <td width="39%">Household Item</td>
    	<td width="59%"><a href="viewServices.php?type=DCHI">View</a></td>
      </tr>
    </table>
    	</td>
      </tr>  
    </table>
    <br>
    		<div align="center">
              <form name="form1" method="post" action="">
        <table width="100%" border="1" cellspacing="0" cellpadding="0" class="font">
          <tr class="text_header_side"> 
            <th width="6%">BIL</th>
            <th width="16%">SERVICE ID</th>
            <th width="40%">SERVICE DESCRIPTION</th>
            <th width="18%">PRICE</th>
          </tr>
          <?php			 
    			  $n=1;
    			  $usrobj = new services;  
    		      $select = "*";
    			  
    			  if(isset($_GET['type']) == "DCG")
    			  {
    				$type=$_GET['type'];
    				$where = "serviceID LIKE '$type%'";
    			  }
    			  else if(isset($_GET['type']) == "DCL")
    			  {
    			  	$type=$_GET['type'];
    				$where = "serviceID LIKE '$type%'";	
    			  }
    			  else if(isset($_GET['type']) == "DCHI")
    			  {
    			  	$type=$_GET['type'];
    				$where = "serviceID LIKE '$type%'";				
    			  } 
    			  else
    			  
                              $where = "";
    	                  $group = "";
    		          $having = "";
    		          $sort = "";		
    			  
    			if (isset($_GET['pageno'])) {
    			
    			$usrobj->setPageno($_GET['pageno']);
    			$n = $usrobj->getCurrentrow($_GET['pageno']) + 1;
    		    } // if
    		    else
    		    {
    		    	$n = 1;
    		    }	
    		
    		      $data = $usrobj->retrieveservices($select, $where, $group, $having, $sort);	
    		      if($data)
    		      {						
    		       foreach($data as $row)
    		    	{		
    		   		  	$servID=$row['serviceID'];
    					$servDesc=$row['serviceDesc'];
    					$servPrice=$row['servicePrice'];
    			  ?>
          <tr class="text"> 
            <td ><div align="center"><?php echo $n;?></div></td>
            <td align="center"><?php echo $servID;?></td>
            <td align="center"><?php echo $servDesc;?></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RM <?php echo $servPrice;?></td>
          </tr>
          <?php
    			  $n++;
    			  	}//foreach
    			  }//if
    			  else
    			  echo '<font color="red"><b>Service is empty.</b></font><br><br>';
    			  ?>
        </table>
        <?php
                   if ($usrobj->pageno == 1)
    				{
    					echo "<font color='#FFFFFF'>Previous</font> ";
    				} //if
    				else
    				{
    				echo "<a href=viewServices.php?pageno=".($usrobj->pageno - 1).">Previous </a> "; 
    				} //else
    				
    				for ($p=1; $p<=$usrobj->lastpage; $p++)
    				{
    				
    					if ($p == $usrobj->pageno)
    					{
    						echo "<a href=viewServices.php?pageno=".$p."><u>".$p."</u></a> "; 
    					} //if
    					else
    					{
    						echo "<a href=viewServices.php?pageno=".$p.">".$p."</a> ";
    					} //else
    					
    				} //for
    				
    				if ($usrobj->pageno == $usrobj->lastpage)
    				{
    					echo "<font color='#FFFFFF'></font>";
    				} //if
    					else
    					{
    					echo "<a href=viewServices.php?pageno=".($usrobj->pageno + 1).">Next</a> "; 
    					} //else
    ?>
      </form>
     </div>
    Entity (servicesEntity.php)
    Code:
    public function setPageno ($pageno)
       {
       		$this->pageno = $pageno;
    		
    		return;
    		
       } //setPageno
       
       
    public function getCurrentrow ($pageno)
       {
       		if ($pageno != 1)
    		{
    			$currentrow = ($pageno - 1) * $this->rows_per_page;
    		}
    		else
    		{
    			$currentrow = 0;
    		}
    		
    		return ($currentrow);
    		
       }
    Can anybody fix this for me?
    Hope to hear from you guys ASAP.
    Thanx
    Last edited by Fariz; Apr 7, 2009, 01:47 AM.
Working...
X