Jump to content

Pagination Error


yash87

Recommended Posts

Hi, Im trying to do pages for my search result. However, when I click on the page number. This error appears (below) :

 

Notice: Undefined index: search in C:\wamp\www\I-Document\new.php on line 8

ERROR: Select from dropdown

 

This message only should appear when there is no input in dropdown and no search input.

Im not sure how to correct this. Please help! Thank u.

 

new.php


<?php

//connecting to the database
include 'config.php';

if (!isset($_POST['submit'])) {
        
    $search = mysql_escape_string($_POST['search']);
$dropdown = empty($_POST['dropdown'])? die ("ERROR: Select from dropdown") : mysql_escape_string($_POST['dropdown']); 

	//max displayed per page
	$per_page = 10;

	//get start variable
	$start = $_GET['start'];

	//count records
	$record_count = mysql_num_rows(mysql_query("SELECT * FROM document"));

	//count max pages
	$max_pages = $record_count / $per_page; //may come out as decimal

	if (!$start)
	   $start = 0;

	//display data
	$query = mysql_query("SELECT * FROM document WHERE $dropdown LIKE '%$search%' LIMIT $start, $per_page");


	echo "<b><center>Search Result</center></b><br>";
     
	$num=mysql_num_rows($query);


	if ($num==0)
			echo "No results found";
		 else
		 {
			echo "$num results found!<p>"; 
		  }
		  
	echo "You searched for <b>$search</b><br /><br /><hr size='1'>";
  
	  echo "<table border='1' width='600'>
			<th>File Reference No.</th>
			<th>File Name</th>
			<th>Owner</th>
			<th>Borrow</th>
			 </tr>";

		while ($rows = mysql_fetch_assoc($query))  
		{
		  echo "<tr>";
		  echo "<td>". $rows['file_ref']  ."</td>";
		  echo "<td>". $rows['file_name'] ."</td>";
		  echo "<td>". $rows['owner'] ."</td>";
		  echo "<td><a href=add_borrower.php?id=" . $rows['id'] . ">Borrow</a></td>";
		  echo "</tr>";
		}
		  echo "</table>"; 
   


	//setup prev and next variables
	$prev = $start - $per_page;
	$next = $start + $per_page;

	//show prev button
	if (!($start<=0))
		   echo "<a href='new.php?start=$prev'>Prev</a> ";

	//show page numbers

	//set variable for first page
	$i=1;

	for ($x=0;$x<$record_count;$x=$x+$per_page)
	{
	 if ($start!=$x)
		echo " <a href='new.php?start=$x'>$i</a> ";
	 else
		echo " <a href='new.php?start=$x'><b>$i</b></a> ";
	 $i++;
	}
}
	//show next button
	if (!($start>=$record_count-$per_page))
		   echo " <a href='new.php?start=$next'>Next</a>";


?>

Link to comment
https://forums.phpfreaks.com/topic/218089-pagination-error/
Share on other sites

ok im  going to take a shot at this but its late and im tired so hope I can still help.

 

this line:

 

  $search = mysql_escape_string($_POST['search'])

 

is pointless post is used to collect values sent using post or send values however a little above that line you typed this:

 

if (!isset($_POST['submit'])) {

 

so your saying that the submit button has not been pushed yet meaning a POST value has not been sent. Or have you redirected yourself to this page using a form on another page?

Link to comment
https://forums.phpfreaks.com/topic/218089-pagination-error/#findComment-1131708
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.