Reputation: 1
I have a check box list of students and a search box in first php page .In ajax page I will get the search results .
But the problem is ,if user selected first search result and searched again selection on the first search is lost
How can I save selections on the first search ?I have tried to make selections in an session array but it is not working
//check list
$qry="select cand_id,name from candidate where inst_id=".$_SESSION['inst_id']."";
$res=$ob->select($qry,$connect);
while($rw=pg_fetch_row($res))
{
echo"<br><input type=\"checkbox\" name=\"check[]\" value=\"$rw[0]\">";echo$rw[1];echo"<br>" ;
}
//Ajax page
if($ajaxData!="")
{
if($_SESSION['usertype_id']==1)
{
$qry="select cand_id,name from candidate where name like'$dataup%' ";
}
else if($_SESSION['usertype_id']==2)
{
$qry="select cand_id,name from candidate where inst_id=".$_SESSION['inst_id']."
and name like'$dataup%' ";
}
$res=$ob->select($qry,$connect);
$words=array();
$count = pg_num_rows($res);
if($count>0)
{
$i=0;
//echo"<div style=\"width: 200px; height: 200px;overflow-y: auto;padding-top: 10px;padding-right: 0px;padding-bottom: 0.25in;\">";
while($rw=pg_fetch_row($res))
{
$words[$i]=$rw[0];$i++;
}
$_SESSION['checkAjax']=$words;//can_id array
$_SESSION['checkAjax']
for highlighting?$_SESSION['checkAjax']
unset on each ajax call?Upvotes: 0
Views: 443
Reputation: 167212
I assume that you are having a code this way for the checkboxes:
<input type="checkbox" name="options[]" value="student"> Student
<input type="checkbox" name="options[]" value="teacher"> Teacher
<input type="checkbox" name="options[]" value="professor"> Professor
If this is the case, you can check it on server side this way, and I again assume it is by POST:
<input type="checkbox" name="options[]" value="student"<?php echo (in_array("student", $_POST["options"])) ? ' checked="checked"' : ''; ?>> Student
<input type="checkbox" name="options[]" value="teacher"<?php echo (in_array("teacher", $_POST["options"])) ? ' checked="checked"' : ''; ?>> Teacher
<input type="checkbox" name="options[]" value="professor"<?php echo (in_array("professor", $_POST["options"])) ? ' checked="checked"' : ''; ?>> Professor
Hope this helps! :)
Upvotes: 1