Jump to content

Pagination not working


nick_whitmarsh

Recommended Posts

Hey guys,

 

I have just gone through the tutorial on this site and cant get pagination to work. Tried Going through my code and still cant get anything.  Here is my code concerned. (sorry about the mess guys)

 

Cheers

 

<?php
session_start();
$pid = ($_SESSION['pid']);

require "../Connect.php";

$query = "select * from member where pid= '".$pid."'";
$result= mysql_query($query,$connection) or die("Unable to perform query $query".mysql_error()); 
$row= mysql_fetch_array($result);
?>

<?php
$limit      = 10;
  $query_count    = "SELECT count(*) FROM messages where pid= '".$pid."'";
     $result_count   = mysql_query($query_count); 
  $totalrows  = mysql_num_rows($result_count); 
  
    if(empty($page)){    // Checks if the $page variable is empty (not set) 
        $page = 1;      // If it is empty, we're on page 1 
    }

 $limitvalue = $page * $limit - ($limit);

  
$query1 = "select * from messages where pid= '".$pid."' LIMIT $limitvalue, $limit";
$result1= mysql_query($query1,$connection) or die("Unable to perform query $query1".mysql_error()); 





  
  


    #$queryer  = "SELECT * FROM table messages $limitvalue, $limit";         
    #$resulter = mysql_query($queryer) or die("Error: " . mysql_error()); 

    if(mysql_num_rows($result1) == 0){ 
        echo("Nothing to Display!"); 
    } 
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Holiday-Friends.Com -->
<!-- Built by Business Information Technology Students -->
<!-- Representing Bournemouth University England -->
<!-- All website built and owned by Adam Dale, Nick Whitmarsh and Daniel Salter -->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Holiday-Friends.Com</title>
<style type="text/css" media="all">

	@import "../css/loggedinsheet.css";

</style>
</head>

<body>

<div id="page">
<div id="container"> 
  <div id="top">
  
  <div id="logo"><a href="index.html"><img src="../logo.PNG" width="298" height="35" border="0" /></a></div>
  
    <div id="top-l"><img src="../f4_1.GIF" /></div>
<div id="top-r"><img src="../f4_2.GIF" /></div>
<?php include ("s-box.html") ?>
  </div>

<?php include ("menu.html") ?>


  <div id="interaction">
<?php include ("box.html") ?>
  </div>
  <div id="advert">advert</div>
  <div id="advert-2">advert 2</div>

  
   <!-- Message Centre -->
   
	 <div id="mc-holder">

 <div id="flash-holder1"> flash animation</div>


     <div id ="mc1">
  
  <a href ="mc-inbox-main.php"><b>Inbox</b></a> |
  <a href ="mc-compose.php">Compose</a> |
  <a href="mc-sent.php">Sent</a> |
</div>
    

  <table width="487" border="0" align="center">
        <tr style="background-color:#F7F7F7">
          <td><table width="476" border="0" align="center">
            <tr style="background-color:#EBEBEB">
              <td width="40">Status</td>
              <td width="30">Delete</td>
              <td width="87">From</td>
              <td width="211">Subject</td>
              <td width="83">Date</td>
            </tr>
           
					  <?php while ($row1= mysql_fetch_array($result1))
		  {?>
		   <tr style="background-color:#FFFFFF">
		 <?php  $from = $row1['sender'];
		  $query3 = "select * from member where pid= '".$from."'";
			$result3= mysql_query($query3,$connection) or die("Unable to perform query $query3".mysql_error()); 
			$row3= mysql_fetch_array($result3);
			$fname = $row3['fname'];
			$sname = $row3['sname'];
			$fname=substr($fname, 0, 1);

		$mid = $row1['mid'];
		$_SESSION['time'] = $row1['time'];

			 $datetime = $row1["time"];
		$year = substr( $datetime, 0, 4 );
		$mon = substr( $datetime, 4, 2 );
		$day = substr( $datetime, 6, 2 );
		$hour = substr( $datetime, 8, 2);
		$min = substr( $datetime, 10, 2 );
		$sec = substr( $datetime, 12, 2 );
		$orgdate = date("j M, Y ", mktime($hour, $min, $sec, $mon, $day, $year ) );
		  
		  ?>
		  
		  <?php
		  $status = $row1['status'];
		  if($status == 0)
		  {
		  	$FILENAME = "inbox-up.gif";

		  }
		  
		  else if($status == 1)
		  {
			$FILENAME = "menu_inbox.gif";
		  }
		  
		  else
		  {
		  	$FILENAME = "inbox-up.gif";
		  }
		  ?>
		  
		  
		  
		  
              <td><img src="../graphics/<?php echo ($FILENAME)?>" /></td>
              <td>
                <input type="checkbox" name="checkbox" value="checkbox" />
              </td>

              <td><?php echo $sname;?>, <?php echo $fname;?></td>
              <td><a href="mc-inbox-read?MID=<?php echo $mid?>&T=<?php echo $row1['time'];?>"><?php echo $row1['subject'];?></a></td>
              <td><?php echo $orgdate;?></td>
		  </tr>
		  <?php } ?>
            
          </table></td>
        </tr>
      </table>
  
  <?php
    if($page != 1){  
        $pageprev = $page--; 

	echo("<a href=\"mc-inbox-main.php&page=$pageprev\">PREV".$limit."</a> ");
	 }else 

echo("PREV"." ");  


	 $numofpages = $totalrows / $limit;
	 for($i = 1; $i <= $numofpages; $i++){
	         if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"mc-inbox-main&page=$i\">$i</a> ");  
        } 
         
}
if(($totalrows % $limit) != 0){ 
       if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"mc-inbox-main&page=$i\">$i</a> "); 
        } 
	}

	if(($totalrows - ($limit * $page)) > 0){ 
	    $pagenext   = $page++; 
		        echo("<a href=\"mc-inbox-main?page=$pagenext\">NEXT".$limit."</a>"); 
        /* Since there are pages remaining, this outputs NEXT in link form. */  
    }else{ 
        echo("NEXT");  
        /* If we're on the last page possible, NEXT will NOT be displayed in link  
form. */ 
    }

?> 

</div>

    


</div>
</div>
</div>

<?php include ("footer.html") ?>
</body>

</html>

Link to comment
Share on other sites

Basically I know I should have had 14 results. I have set a limit of 10 of these to show, then the other 4 show on the next page. However all it shows is PREV 1 NEXT. It does not give an option to click and go onto another page to display the results.

 

The whole pricnicple of pagination is not working.

 

Cheers

Link to comment
Share on other sites

Are you 100% sure that there are supposed to be two pages being shown?

 

Can you echo out $totalrows after setting it?

 

$totalrows  = mysql_num_rows($result_count); 
echo 'Total rows: '.$totalsrows.'<br />';

 

The reason why i wanted to make sure is that this would be the correct behaviour of the pagination if there was only one page, and i cant spot anything obviously wrong with the code at the moment.

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.