I'm trying to paginate my search results. The first page comes up just fine, but when I click to go to the next page, this happens:

Notice: Undefined index: d1 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 2

Notice: Undefined index: d2 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 3

Notice: Undefined index: p1 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 4

Notice: Undefined index: p2 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 5

Notice: Undefined index: p3 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 6

Notice: Undefined index: p4 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 7

Notice: Undefined index: r1 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 8

Notice: Undefined index: r2 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 9

Notice: Undefined index: r3 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 10

Notice: Undefined index: r4 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 11

Notice: Undefined index: r5 in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 12

Notice: Undefined index: minsts in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 13

Notice: Undefined index: maxsts in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 14

Notice: Undefined index: minchg in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 15

Notice: Undefined index: maxchg in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 16

Notice: Undefined index: minsatv in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 17

Notice: Undefined index: maxsatv in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 18

Notice: Undefined index: minsatm in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 19

Notice: Undefined index: maxsatm in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 20

Notice: Undefined index: minsatw in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 21

Notice: Undefined index: maxsatw in D:\Website Design Environment\EasyPHP-5.3.8.1\www\jquery_ui\process.php on line 22
SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( () OR () ) AND ( () OR () OR () OR () ) AND ( () OR () OR () OR () OR () ) AND (TOTAL_STS BETWEEN AND ) AND (TOTAL_CHG BETWEEN AND ) AND (SAT_VR_AVG BETWEEN AND ) AND (SAT_MT_AVG BETWEEN AND ) AND (SAT_WR_AVG BETWEEN AND )Error processing query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') OR () ) AND ( () OR () OR () OR () ) AND ( () OR () OR () OR () OR () ) AND (T' at line 1

Those variables are all from a form that the user fills out. AJAX then brings in the results as the user makes selections. If the user makes a change, the results refresh, but I don't know how to get the PHP pagination to work accordingly. I've browsed a bunch of forums, but I can't figure out exactly how to apply it to my situation. Here's my processing PHP:

<?php
$d1=$_POST['d1'];
$d2=$_POST['d2'];
$p1=$_POST['p1'];
$p2=$_POST['p2'];
$p3=$_POST['p3'];
$p4=$_POST['p4'];
$r1=$_POST['r1'];
$r2=$_POST['r2'];
$r3=$_POST['r3'];
$r4=$_POST['r4'];
$r5=$_POST['r5'];
$minsts=$_POST['minsts'];
$maxsts=$_POST['maxsts'];
$minchg=$_POST['minchg'];
$maxchg=$_POST['maxchg'];
$minsatv=$_POST['minsatv'];
$maxsatv=$_POST['maxsatv'];
$minsatm=$_POST['minsatm'];
$maxsatm=$_POST['maxsatm'];
$minsatw=$_POST['minsatw'];
$maxsatw=$_POST['maxsatw'];

require "connect_to_mysql.php";
// Start the SQL string
$sql = "SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( ($d1) OR ($d2) ) AND ( ($p1) OR ($p2) OR ($p3) OR ($p4) ) AND ( ($r1) OR ($r2) OR ($r3) OR ($r4) OR ($r5) ) AND (TOTAL_STS BETWEEN $minsts AND $maxsts) AND (TOTAL_CHG BETWEEN $minchg AND $maxchg) AND (SAT_VR_AVG BETWEEN $minsatv AND $maxsatv) AND (SAT_MT_AVG BETWEEN $minsatm AND $maxsatm) AND (SAT_WR_AVG BETWEEN $minsatw AND $maxsatw)";
print_r($sql);

	$result = mysql_query($sql) or die("Error processing <strong>query</strong>. ".mysql_error());
	$row = mysql_fetch_assoc($result) or die("No rows returned by query");
	echo "<form method = 'post' action = 'schoolme_details_new.php'>";
	while($row = mysql_fetch_assoc($result)){
		echo "<img src='colleges/".$row['UNITID']."/tb/tb_01.jpg' alt='no pic'/>
				<div><h3>".$row['NAME_SCH']."</h3>
				<p>U.S. News 排名: ".$row['CTRL_SCH']."<br />
				   每年的费用: ".$row['TOTAL_CHG']."<br />
				   录取率: ".$row['ACCEPT_RATE']."<br />
				   全部学生数: ".$row['TOTAL_STS']."<br />
				   <input type='radio' onclick='this.form.submit()' name = 'UNITID' value='".$row['UNITID']."' />
				   <br />
				   <br />
				</p>
				<p></p>
			</div></form>";
	}
	
 //This checks to see if there is a page number. If not, it will set it to page 1 

 if (!(isset($pagenum))) 

 { 

 $pagenum = 1; 

 } 

 

 //Here we count the number of results 

 //Edit $data to be your query 

 $data = mysql_query($sql) or die("Error processing <strong>query</strong>. ".mysql_error()); 

 $rows = mysql_num_rows($data); 

 

 //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; 

//This is your query again, the same one... the only difference is we add $max into it

 $data_p = mysql_query("SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( ($d1) OR ($d2) ) AND ( ($p1) OR ($p2) OR ($p3) OR ($p4) ) AND ( ($r1) OR ($r2) OR ($r3) OR ($r4) OR ($r5) ) AND (TOTAL_STS BETWEEN $minsts AND $maxsts) AND (TOTAL_CHG BETWEEN $minchg AND $maxchg) AND (SAT_VR_AVG BETWEEN $minsatv AND $maxsatv) AND (SAT_MT_AVG BETWEEN $minsatm AND $maxsatm) AND (SAT_WR_AVG BETWEEN $minsatw AND $maxsatw) $max") or die(mysql_error()); 


 //This is where you display your query results

 while($info = mysql_fetch_array( $data_p )) 

 { 

 Print $info['UNITID']; 

 echo "<br>";

 } 

 echo "<p>";

 
 // This shows the user what page they are on, and the total number of pages

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

 
 // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.

 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> ";

 }
?>

Thanks in advance for the help!

When you switch from page 1 to page 2, then your $_POST variables are gone. If you need them on all pages, I suggest you store them in $_SESSION variables.

When you switch from page 1 to page 2, then your $_POST variables are gone. If you need them on all pages, I suggest you store them in $_SESSION variables.

Thanks, but I'm still coming up with the same problem. Never knew what $_SESSION was for. Hehe. Anyway, looked easy enough. I did the following code, and came up with the same problem. Same "undefined variable" problem as before. I know it must be because its reprocessing the stuff at the top every time I go to the next page. How do I get around that? Thanks! Here's the code:

<?php
session_start();
$_SESSION['d1']=$_POST['d1'];
$_SESSION['d2']=$_POST['d2'];
$_SESSION['p1']=$_POST['p1'];
$_SESSION['p2']=$_POST['p2'];
$_SESSION['p3']=$_POST['p3'];
$_SESSION['p4']=$_POST['p4'];
$_SESSION['r1']=$_POST['r1'];
$_SESSION['r2']=$_POST['r2'];
$_SESSION['r3']=$_POST['r3'];
$_SESSION['r4']=$_POST['r4'];
$_SESSION['r5']=$_POST['r5'];
$_SESSION['minsts']=$_POST['minsts'];
$_SESSION['maxsts']=$_POST['maxsts'];
$_SESSION['minchg']=$_POST['minchg'];
$_SESSION['maxchg']=$_POST['maxchg'];
$_SESSION['minsatv']=$_POST['minsatv'];
$_SESSION['maxsatv']=$_POST['maxsatv'];
$_SESSION['minsatm']=$_POST['minsatm'];
$_SESSION['maxsatm']=$_POST['maxsatm'];
$_SESSION['minsatw']=$_POST['minsatw'];
$_SESSION['maxsatw']=$_POST['maxsatw'];

require "connect_to_mysql.php";
// Start the SQL string
$sql = "SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( (".$_SESSION['d1'].") OR (".$_SESSION['d2'].") ) AND ( (".$_SESSION['p1'].") OR (".$_SESSION['p2'].") OR (".$_SESSION['p3'].") OR (".$_SESSION['p4'].") ) AND ( (".$_SESSION['r1'].") OR (".$_SESSION['r2'].") OR (".$_SESSION['r3'].") OR (".$_SESSION['r4'].") OR (".$_SESSION['r5'].") ) AND (TOTAL_STS BETWEEN ".$_SESSION['minsts']." AND ".$_SESSION['maxsts'].") AND (TOTAL_CHG BETWEEN ".$_SESSION['minchg']." AND ".$_SESSION['maxchg'].") AND (SAT_VR_AVG BETWEEN ".$_SESSION['minsatv']." AND ".$_SESSION['maxsatv'].") AND (SAT_MT_AVG BETWEEN ".$_SESSION['minsatm']." AND ".$_SESSION['maxsatm'].") AND (SAT_WR_AVG BETWEEN ".$_SESSION['minsatw']." AND ".$_SESSION['maxsatw'].")";
print_r($sql);

	$result = mysql_query($sql) or die("Error processing <strong>query</strong>. ".mysql_error());
	$row = mysql_fetch_assoc($result) or die("No rows returned by query");
	echo "<form method = 'post' action = 'schoolme_details_new.php'>";
	while($row = mysql_fetch_assoc($result)){
		echo "<img src='colleges/".$row['UNITID']."/tb/tb_01.jpg' alt='no pic'/>
				<div><h3>".$row['NAME_SCH']."</h3>
				<p>U.S. News 排名: ".$row['CTRL_SCH']."<br />
				   每年的费用: ".$row['TOTAL_CHG']."<br />
				   录取率: ".$row['ACCEPT_RATE']."<br />
				   全部学生数: ".$row['TOTAL_STS']."<br />
				   <input type='radio' onclick='this.form.submit()' name = 'UNITID' value='".$row['UNITID']."' />
				   <br />
				   <br />
				</p>
				<p></p>
			</div></form>";
	}
	
 //This checks to see if there is a page number. If not, it will set it to page 1 

 if (!(isset($pagenum))) 

 { 

 $pagenum = 1; 

 } 

 

 //Here we count the number of results 

 //Edit $data to be your query 

 $data = mysql_query($sql) or die("Error processing <strong>query</strong>. ".mysql_error()); 

 $rows = mysql_num_rows($data); 

 

 //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; 

//This is your query again, the same one... the only difference is we add $max into it

 $data_p = mysql_query("SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( (".$_SESSION['d1'].") OR (".$_SESSION['d2'].") ) AND ( (".$_SESSION['p1'].") OR (".$_SESSION['p2'].") OR (".$_SESSION['p3'].") OR (".$_SESSION['p4'].") ) AND ( (".$_SESSION['r1'].") OR (".$_SESSION['r2'].") OR (".$_SESSION['r3'].") OR (".$_SESSION['r4'].") OR (".$_SESSION['r5'].") ) AND (TOTAL_STS BETWEEN ".$_SESSION['minsts']." AND ".$_SESSION['maxsts'].") AND (TOTAL_CHG BETWEEN ".$_SESSION['minchg']." AND ".$_SESSION['maxchg'].") AND (SAT_VR_AVG BETWEEN ".$_SESSION['minsatv']." AND ".$_SESSION['maxsatv'].") AND (SAT_MT_AVG BETWEEN ".$_SESSION['minsatm']." AND ".$_SESSION['maxsatm'].") AND (SAT_WR_AVG BETWEEN ".$_SESSION['minsatw']." AND ".$_SESSION['maxsatw'].") $max") or die(mysql_error()); 


 //This is where you display your query results

 while($info = mysql_fetch_array( $data_p )) 

 { 

 Print $info['UNITID']; 

 echo "<br>";

 } 

 echo "<p>";

 
 // This shows the user what page they are on, and the total number of pages

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

 
 // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.

 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> ";

 }
?>

Blindly copying $_POST variables into $_SESSION variables is doing nothing different than your first script.

At the very minimum you should be doing a isset() check on them to see if they contain any data before assigning the session variable. That way you won't be overwriting the session contents with null values.

Alternatively, use $_REQUEST to fetch the values, and in any links you create add the key value pairs you need to the query string.

Blindly copying $_POST variables into $_SESSION variables is doing nothing different than your first script.

At the very minimum you should be doing a isset() check on them to see if they contain any data before assigning the session variable. That way you won't be overwriting the session contents with null values.

Alternatively, use $_REQUEST to fetch the values, and in any links you create add the key value pairs you need to the query string.

Thanks! As you can probably tell, I'm new to all of this... about 2 months now of learning HTML, CSS, PHP, SQL, and jQuery by myself. The code with an explanation has helped me learn quite a bit these past couple of months, even if not necessarily in the correct order. I have looked at what isset() does and $_REQUEST and $_SESSION, but I don't know how in the world I'm supposed to put it all together. If you're not able to post code specifically to give me, perhaps you could post example code and an explanation. Thanks again!

- Your local noob

Member Avatar for diafol
$d1 = (isset($_POST['d1'])) ? $_POST['d1'] : 'default value';

you can do that sort of thing - obviously give your default value a real value :)

If you mean to use this data in different pages thereafter:

session_start();
$d1 = (isset($_POST['d1'])) ? $_POST['d1'] : 'default value';
$_SESSION['d1']  = $d1;
//etc

Okay. Thanks, ardav. That put me on the right track. I also then took a pagination tutorial over at developphp. Problem is, when I click for a different page, e.g. "next", I lose the rest of my template. As I stated in my title, I'm really trying to get not only dynamic pagination, but dynamic pagination for a dynamic search. That way, the dynamic search results end up in a <div>, and the user can page through those results without being redirected to a whole other page. This way they can still make changes on the dynamic search at any time, thereby refreshing the results all on the same page. Is this something I'll have to take care of with jQuery? I'm already using jQuery and AJAX with the dynamic search part. So, does anyone know how I can do both, or should I start a new thread for this specifically. Thanks again, guys, for the help! I learned a lot about using $_SESSION through this, and here's what I did for my code:

<?php
session_start();
if (empty($_POST['d1'])) {$_POST['d1']=$_SESSION['d1'];}else{$_POST['d1']=$_POST['d1'];}
if (empty($_POST['d2'])) {$_POST['d2']=$_SESSION['d2'];}else{$_POST['d2']=$_POST['d2'];}
if (empty($_POST['p1'])) {$_POST['p1']=$_SESSION['p1'];}else{$_POST['p1']=$_POST['p1'];}
if (empty($_POST['p2'])) {$_POST['p2']=$_SESSION['p2'];}else{$_POST['p2']=$_POST['p2'];}
if (empty($_POST['p3'])) {$_POST['p3']=$_SESSION['p3'];}else{$_POST['p3']=$_POST['p3'];}
if (empty($_POST['p4'])) {$_POST['p4']=$_SESSION['p4'];}else{$_POST['p4']=$_POST['p4'];}
if (empty($_POST['r1'])) {$_POST['r1']=$_SESSION['r1'];}else{$_POST['r1']=$_POST['r1'];}
if (empty($_POST['r2'])) {$_POST['r2']=$_SESSION['r2'];}else{$_POST['r2']=$_POST['r2'];}
if (empty($_POST['r3'])) {$_POST['r3']=$_SESSION['r3'];}else{$_POST['r3']=$_POST['r3'];}
if (empty($_POST['r4'])) {$_POST['r4']=$_SESSION['r4'];}else{$_POST['r4']=$_POST['r4'];}
if (empty($_POST['r5'])) {$_POST['r5']=$_SESSION['r5'];}else{$_POST['r5']=$_POST['r5'];}
if (empty($_POST['minsts'])) {$_POST['minsts']=$_SESSION['minsts'];}else{$_POST['minsts']=$_POST['minsts'];}
if (empty($_POST['maxsts'])) {$_POST['maxsts']=$_SESSION['maxsts'];}else{$_POST['maxsts']=$_POST['maxsts'];}
if (empty($_POST['minchg'])) {$_POST['minchg']=$_SESSION['minchg'];}else{$_POST['minchg']=$_POST['minchg'];}
if (empty($_POST['maxchg'])) {$_POST['maxchg']=$_SESSION['maxchg'];}else{$_POST['maxchg']=$_POST['maxchg'];}
if (empty($_POST['minsatv'])) {$_POST['minsatv']=$_SESSION['minsatv'];}else{$_POST['minsatv']=$_POST['minsatv'];}
if (empty($_POST['maxsatv'])) {$_POST['maxsatv']=$_SESSION['maxsatv'];}else{$_POST['maxsatv']=$_POST['maxsatv'];}
if (empty($_POST['minsatm'])) {$_POST['minsatm']=$_SESSION['minsatm'];}else{$_POST['minsatm']=$_POST['minsatm'];}
if (empty($_POST['maxsatm'])) {$_POST['maxsatm']=$_SESSION['maxsatm'];}else{$_POST['maxsatm']=$_POST['maxsatm'];}
if (empty($_POST['minsatw'])) {$_POST['minsatw']=$_SESSION['minsatw'];}else{$_POST['minsatw']=$_POST['minsatw'];}
if (empty($_POST['maxsatw'])) {$_POST['maxsatw']=$_SESSION['maxsatw'];}else{$_POST['maxsatw']=$_POST['maxsatw'];}

$_SESSION['d1']=$_POST['d1'];
$_SESSION['d2']=$_POST['d2'];
$_SESSION['p1']=$_POST['p1'];
$_SESSION['p2']=$_POST['p2'];
$_SESSION['p3']=$_POST['p3'];
$_SESSION['p4']=$_POST['p4'];
$_SESSION['r1']=$_POST['r1'];
$_SESSION['r2']=$_POST['r2'];
$_SESSION['r3']=$_POST['r3'];
$_SESSION['r4']=$_POST['r4'];
$_SESSION['r5']=$_POST['r5'];
$_SESSION['minsts']=$_POST['minsts'];
$_SESSION['maxsts']=$_POST['maxsts'];
$_SESSION['minchg']=$_POST['minchg'];
$_SESSION['maxchg']=$_POST['maxchg'];
$_SESSION['minsatv']=$_POST['minsatv'];
$_SESSION['maxsatv']=$_POST['maxsatv'];
$_SESSION['minsatm']=$_POST['minsatm'];
$_SESSION['maxsatm']=$_POST['maxsatm'];
$_SESSION['minsatw']=$_POST['minsatw'];
$_SESSION['maxsatw']=$_POST['maxsatw'];

require "connect_to_mysql.php";

$sql = "SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( (".$_SESSION['d1'].") OR (".$_SESSION['d2'].") ) AND ( (".$_SESSION['p1'].") OR (".$_SESSION['p2'].") OR (".$_SESSION['p3'].") OR (".$_SESSION['p4'].") ) AND ( (".$_SESSION['r1'].") OR (".$_SESSION['r2'].") OR (".$_SESSION['r3'].") OR (".$_SESSION['r4'].") OR (".$_SESSION['r5'].") ) AND (TOTAL_STS BETWEEN ".$_SESSION['minsts']." AND ".$_SESSION['maxsts'].") AND (TOTAL_CHG BETWEEN ".$_SESSION['minchg']." AND ".$_SESSION['maxchg'].") AND (SAT_VR_AVG BETWEEN ".$_SESSION['minsatv']." AND ".$_SESSION['maxsatv'].") AND (SAT_MT_AVG BETWEEN ".$_SESSION['minsatm']." AND ".$_SESSION['maxsatm'].") AND (SAT_WR_AVG BETWEEN ".$_SESSION['minsatw']." AND ".$_SESSION['maxsatw'].")";

	$sql = mysql_query($sql) or die("Error processing <strong>query</strong>. ".mysql_error());

$nr = mysql_num_rows($sql); 
if (isset($_GET['pn'])) { 
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); 
} else { 
    $pn = 1;
}
$itemsPerPage = 10;
$lastPage = ceil($nr / $itemsPerPage);
if ($pn < 1) { 
    $pn = 1; 
} else if ($pn > $lastPage) { 
    $pn = $lastPage; 
}
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
}
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;

$sql2 = mysql_query("SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( (".$_SESSION['d1'].") OR (".$_SESSION['d2'].") ) AND ( (".$_SESSION['p1'].") OR (".$_SESSION['p2'].") OR (".$_SESSION['p3'].") OR (".$_SESSION['p4'].") ) AND ( (".$_SESSION['r1'].") OR (".$_SESSION['r2'].") OR (".$_SESSION['r3'].") OR (".$_SESSION['r4'].") OR (".$_SESSION['r5'].") ) AND (TOTAL_STS BETWEEN ".$_SESSION['minsts']." AND ".$_SESSION['maxsts'].") AND (TOTAL_CHG BETWEEN ".$_SESSION['minchg']." AND ".$_SESSION['maxchg'].") AND (SAT_VR_AVG BETWEEN ".$_SESSION['minsatv']." AND ".$_SESSION['maxsatv'].") AND (SAT_MT_AVG BETWEEN ".$_SESSION['minsatm']." AND ".$_SESSION['maxsatm'].") AND (SAT_WR_AVG BETWEEN ".$_SESSION['minsatw']." AND ".$_SESSION['maxsatw'].") $limit");

$paginationDisplay = ""; 
if ($lastPage != "1"){
    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
    }
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
    }
}

	$row = mysql_fetch_assoc($sql2) or die("No rows returned by query");

$outputList = '';
	while($row = mysql_fetch_assoc($sql2)){
		$outputList .= "<form method = 'post' action = 'schoolme_details_new.php'>
		      <div><h3>".$row['NAME_SCH']."</h3>
				<p>U.S. News 排名: ".$row['CTRL_SCH']."<br />
				   每年的费用: ".$row['TOTAL_CHG']."<br />
				   录取率: ".$row['ACCEPT_RATE']."<br />
				   全部学生数: ".$row['TOTAL_STS']."<br />
				   <input type='radio' onclick='this.form.submit()' name = 'UNITID' value='".$row['UNITID']."' />
				   <br />
				   <br />
				</p>
				<p></p>
			</div></form>";
	}

?>
<html>
<head>
<style type="text/css">
<!--
.pagNumActive {
    color: #000;
    border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:link {
    color: #000;
    text-decoration: none;
    border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:visited {
    color: #000;
    text-decoration: none;
    border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:hover {
    color: #000;
    text-decoration: none;
    border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:active {
    color: #000;
    text-decoration: none;
    border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
-->
</style>
</head>
<body>
  <div style="margin-left:64px; margin-right:64px;">
    <h2>Total Items: <?php echo $nr; ?></h2>
  </div>
  <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
  <div style="margin-left:64px; margin-right:64px;"><?php print "$outputList"; ?></div>
  <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
</body>
</html>
Member Avatar for diafol

You're using unsanitized data in your sql. You have to clean it.

Again, thank you. Seems like that will be the least of my worries, though, if I can't get this thing to work. I just sanitized it, though, so thanks. Maybe an example of what I'm trying to do will help. http://www.zinch.com/undergradschool/search Anyway, I certainly appreciate the help. The members on this forum have taught me tons in the past couple of months.

Member Avatar for diafol

Using post variables and session variables for operations or modifying post data in a page is a bit odd. As a rule, you'd place the input data into a new 'clean' variable.

$sql2 = mysql_query("SELECT * FROM post_sec_master WHERE 1=1 AND ROOM=1 AND OPEN_DEG_POSTSEC_SCH=1 AND ( (".$_SESSION['d1'].") OR (".$_SESSION['d2'].") ) AND ( (".$_SESSION['p1'].") OR (".$_SESSION['p2'].") OR (".$_SESSION['p3'].") OR (".$_SESSION['p4'].") ) AND ( (".$_SESSION['r1'].") OR (".$_SESSION['r2'].") OR (".$_SESSION['r3'].") OR (".$_SESSION['r4'].") OR (".$_SESSION['r5'].") ) AND (TOTAL_STS BETWEEN ".$_SESSION['minsts']." AND ".$_SESSION['maxsts'].") AND (TOTAL_CHG BETWEEN ".$_SESSION['minchg']." AND ".$_SESSION['maxchg'].") AND (SAT_VR_AVG BETWEEN ".$_SESSION['minsatv']." AND ".$_SESSION['maxsatv'].") AND (SAT_MT_AVG BETWEEN ".$_SESSION['minsatm']." AND ".$_SESSION['maxsatm'].") AND (SAT_WR_AVG BETWEEN ".$_SESSION['minsatw']." AND ".$_SESSION['maxsatw'].") $limit");

That's just horrible to debug. What's the 1=1 trying to achieve?

Also your concatenations - you don't need to use so many dots - difficult to keep track of all of them :):

$paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';

Try:

$paginationDisplay .=  "&nbsp;  <a href=\"{$_SERVER['PHP_SELF']}?pn=$nextPage\"> Next</a> ";

Just escape double quotes and put brackets {} around array items. Sometimes placing a bracket around a regular variable is impt if you want to join a var and a word with no other character between them. Anyway, makes for easier reading for me - not to everybody's taste.

A final thank you for your help. I was able to finish up the PHP for dynamic pagination after all the help here (and lots of googling), but I went the jQuery way after realizing that it's basically the only approach for my situation, i.e. dynamic search with dynamic pagination in a DIV. And as for my quircky coding, well, chalk that up to learning a lot of stuff in a little time from an absurd amount of resources. And believe it or not, I like the dots :-) Peace, bro! Problem solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.