I have a form that submits parameters using standard HTML controls to a PHP file. The PHP file then iterates through a csv file and returns the resuts via AJAX. If I select a dropdown menu from the form I get the data back no problem but when I then make another selection it doesn’t remember what I have previously selected so only the new parameter gets submitted. How do I ensure the previous selected control(s) get submitted? Any ideas or suggestions greatly appreciated.
search.php:
<?php
error_reporting(E_ALL & ~E_NOTICE);
require_once('includes/MagicParser.php');
$key = $_GET['key'];
$search = $_GET['search'];
$counter = 0;
function recordHandler($record)
{
global $key;
global $search;
global $counter;
if ($record[$key] == $search) {
if ($counter % 2) {
print "<tr class=\"alt_row\">";
} else {
print "<tr>";
}
print "<td>".$record['Subject']."</td>";
print "<td>".$record['Tutor']."</td>";
print "<td>".$record['Level']."</td>";
print "<td>".$record['Course Type']."</td>";
print "<td>".$record['Course Code']."</td>";
print "<td>".$record['Primary Center']."</td>";
print "<td>".$record['Lesson 1 Date']."</td>";
print "<td><a href=\"#\"></a></td>";
print "<td><a href=\"#\"></a></td></td>";
print "</tr>";
} else {
return;
}
$counter ++;
}
print "
<table id=\"results\">
<tr>
<th>Subject</th>
<th>Tutor</th>
<th>Level</th>
<th>Type</th>
<th>Code</th>
<th>Center</th>
<th>Date</th>
<th>Timetable</th>
<th>Outline</th>
</tr>
";
MagicParser_parse("includes/course-data.csv", "recordHandler");
print "
</table>
<div id=\"pager_display\"></div>
";
?>
scripts.js:
function showCourse(search, key)
{
if (search == "") {
document.getElementById("dynamic_display").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("dynamic_display").innerHTML = xmlhttp.responseText;
pager = new Pager('results', 15);
pager.init();
pager.showPageNav('pager', 'pager_display');
pager.showPage(1);
}
}
xmlhttp.open("GET", "search.php?key="+ key +"&search=" + search, true);
xmlhttp.send();
}
/*
function disableEnableForm(form, boolean)
{
var formElements = form.elements;
for (i = 0; i < form.length; i ++) {
formElements[i].disabled = boolean;
}
}
*/
I would store them in
$_SESSION. However, even once you get that squared away your basic search logic doesnt allow for multiple parameters so youll need to reconfigure that as well.. It might look something like the following:This isnt by any means complete Im not sure exactly how your parser works and all that fun stuff – and this only supports an
ANDsearch – it will only return rows which match all supplied key-value pairs in the search. You would also need to implement something to clear the search parameters so the user can start over too. But you should be bale to get the basic idea…