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!