Jump to content

Help with php pagination please


deansaddigh

Recommended Posts

Hi guys im following this tutorial on pagination

http://php.about.com/od/phpwithmysql/ss/php_pagination.htm

 

Pages 1-4 takes me through the tutorial, on page 3 they add a $max variable which is my problem.

 

Heres my code

<?php 
	  	/***************
	   	* Get  enquiries
	   	**********************************************************************/
		//This checks to see if there is a page number. If not, it will set it to page 1
		if (!(isset($pagenum)))
		{
		$pagenum = 1;
		}



		  $query = "SELECT * FROM enquiry $max ORDER BY date DESC";
		  			 
					$result = mysql_query($query, $conn)
					or die ("Unable to perform query");
					//Get number of rows	
					$rows = mysql_num_rows($result);


				//This is the number of results displayed per page
				$page_rows = 4;

				//This tells us the page number of our last page
				$last = ceil($rows/$page_rows);

				//this makes sure the page number isn't below one, or more than our maximum pages
				if ($pagenum < 1)
				{
				$pagenum = 1;
				}
				elseif ($pagenum > $last)
				{
				$pagenum = $last;
				}

				//This sets the range to display in our query
				$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

		  

			while($row= mysql_fetch_array($result))
			{	
				$id = $row['enquiry_id'];
			  	echo '<strong>Subject:</strong>'.' '.$row['subject'].'<br/>';
			  	echo '<strong>Message:</strong>'. ' '.$row['content'].'<br/><br/>';
			  	echo '<strong>Email:</strong>'. ' '.$row['email']. '<br/>';
				echo '<strong>Name:</strong>'. ' '.$row['first_name'];
				echo $row['surname'].'<br/>';
				echo'<strong> This enquiry was made on:</strong> ' .$row['date'].'<br/>';
				  
				if($row['replied'] == 'yes')
			  	{	
			  	    echo '<img src="images/tick.png" alt="replied" class="floatright" /><br/><br/>';
			  		echo '<strong class="replied">You have replied Your message was:</strong><br/><br/>';
					echo '<strong><p class="important">'.$row['replied_back'].'</p></strong><hr/>';
			    }
				elseif($row['replied'] == 'no')
				{	
					echo '<img src="images/cross.png" alt="replied" class="floatright" /><br/><br/>';
					echo '<strong class="notreplied">You have not replied</strong><br/>';
					echo '<a href="enquiry_reply.php?id='.$id.'">Reply now!</a><hr/> ';
			    }
			}


		//pagination

		echo " --Page $pagenum of $last-- <p>";

		if ($pagenum == 1)
		{
		}
		else
		{
		echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
		echo " ";
		$previous = $pagenum-1;
		echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
		}

		//just a spacer
		echo " ---- ";

		//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
		if ($pagenum == $last)
		{
		}
		else {
		$next = $pagenum+1;
		echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
		echo " ";
		echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
		} 

  ?>

 

Im getting this error

Notice: Undefined variable: max in \\nas44ent\domains\l\languageschoolsuk.com\user\htdocs\admin\view_enquiries.php on line 52

 

Saying undifined variable $max, which i understand because i havent initialised it. but in the tutorial i cant see where they are doing it.

 

Can anyone point me in the right direction if possible.

 

Kind regards

 

Dean  :D

Link to comment
https://forums.phpfreaks.com/topic/193454-help-with-php-pagination-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.