Jump to content

Recommended Posts

Hi all,

 

I have been working on this since my last post. I now have the pagination working so that it knows hoe many pages there are and how to display the numbers.

 

However my problem comes that if I press next it then only displays the first set of results. I have it so that it displays ten messages in this case. However when I click next it still displays the first ten messages and not the next six (because I know there are 16 messages on total. Thats the easy bit to work out)

 

I'm sure it is something simple but I think I've looked at it so much im missing it.

 

Cheers Guys.

 

<?php
session_start();
$page = $_GET['page'];

$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);
  
$query1 = "select * from messages where pid= '".$pid."'";
$result1= mysql_query($query1,$connection) or die("Unable to perform query $query1".mysql_error()); 
$num_record = mysql_num_rows($result1);
$display = 13; 
$XX = 'Sorry, no results were found!'; 
if (empty($startrow)) { 
    $startrow=0; 
} 

$queryz = "SELECT * FROM messages WHERE pid= '".$pid."' LIMIT $startrow, $display"; 
$resultz = mysql_query($queryz); 

$counter = 0; 
?>


<!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(list($Fields) = mysql_fetch_array($resultz)) { 
			if ($counter == 3) 
			{ 
				$counter = 0; 
			}?>

			<?php while ($row1= mysql_fetch_array($resultz))
		  {?>


		   <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
$counter = $counter + 1; 
  }?>
		  <?php } ?>
  		
          </table></td>
        </tr>
      </table>
  
  <?php
  if ($startrow != 0) 
  { 
    	$prevrow = $startrow - $display; 
    	echo("<a href=\"$PHP_SELF?startrow=$prevrow\">Previous</a> "); 
  } 
  
  $pages = intval($num_record / $display); 
  if ($num_record % $display) 
  { 
	    $pages++; 
  }
  
  if ($pages > 1) 
  {  
  	for ($i=1; $i <= $pages; $i++) 
	{
		$nextrow = $display * ($i - 1); 
		echo("<a href=\"$PHP_SELF?startrow=$nextrow\">$i</a>  ");
	}
  }
  
  if (!(($startrow / $display) == $pages) && $pages != 1) 
  {
  	$nextrow = $startrow + $display; 
	echo("<a href=\"$PHP_SELF?startrow=$nextrow\">Next</a>"); 
  }
  if ($num_record < 1) { 
    echo("<table border=0 width=795><tr><td>$XX</td></tr></table>"); 
} 



  
  ?>
	  


</div>

    


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

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

</html>

Link to comment
https://forums.phpfreaks.com/topic/63780-im-stumped-now-pagination/
Share on other sites

When does $startrow ever become anything other than 0. I see you have a $page variable defined, shouldnt you be using that to determine what $startrow is? How are you getting the current page number, or offset, you are on?

 

like, $startrow = floor( ($page * $display) );

Ok I got that fixed. I was being thick. Your advise was very useful.

 

Anyways. Now that it is displaying the results it does not show all of them. For example, a message consists of a receiver a sender a subject and a body. However if the subject name are correct then it only shows one of the messages. The last one.

 

Any ideas why?

 

Cheers

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.