This page basically displays a table of a list of options from DB that a user can select, once selected the user is give the option to remove the selected option should they have made a mistake. I have taken out all of the unnecessary stuff to make it easier to follow. I have tried every combination to get a session array element to unset and have pretty much given up. I know the posted values are working ok as i have had them echoing back to the screen after submitting the form. The array_search function does not seem to like a variable name, if I replace $ss_id with a physical value I can get it to unset ok.
Any suggestions would be greatly appreciated.
<?php require_once('Connections/fs1.php');
if (!isset($_SESSION)) {
session_start();
}
if (!isset($_SESSION['con29']))
{
$_SESSION['con29'] = array();
}
//db call to get con29 options
$query1 = mysql_query("SELECT * FROM sub_search_content") or die(mysql_error());
$_SESSION['main_search_selected'] = 's7';
$main_search_selected = $_SESSION['main_search_selected'];
//setup the session variables depending on what was posted------------------
if (isset($_POST['sub_search_content_id']))//add an option
{
$row_id_1 = $_POST['sub_search_content_id'];
array_push($_SESSION['con29'],$row_id_1);
}
if (isset($_POST['sub_search_content_id_remove']))
{
$ss_id = $_POST['sub_search_content_id_remove'];
$key=array_search($ss_id,$_SESSION['con29']);
if($key!==false) unset($_SESSION['con29'][$key]);
//echo $ss_id;
//echo $key;
}
//print_r ($_SESSION['con29']);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<?php
while ($row = mysql_fetch_assoc($query1))
{
$sub_search_id = $_SESSION['con29'];
if($row[$main_search_selected] == 1)
{
$bgcolour = '#ffffff';
$select_row ='';
$select_row_2='';
}
elseif($row[$main_search_selected] == 2)
{
$id = $row['sub_search_content_id'];
$key = array_search($id, $sub_search_id);
if($key != '')
{
$bgcolour = '#AFC137';
$select_row = '<input name="submit" class="push_buttons" type="submit" value="Remove" />';
$select_row_2 = '<input name="sub_search_content_id_remove" type="hidden" id="sub_search_content_id_remove" value="' . $row['sub_search_content_id'] .' " />';
}
else
{
$bgcolour = '#ffffff';
$select_row = '<input name="submit" class="push_buttons" type="submit" value="select" />';
$select_row_2 = '<input name="sub_search_content_id" type="hidden" id="sub_search_content_id" value="' . $row['sub_search_content_id'].'" />';
}
}
elseif($row[$main_search_selected] == 3)
{
$bgcolour = '#FF9900';
$select_row = "Included";
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($row[$main_search_selected] != 1)
{ ?>
<tr bgcolor="<?php echo $bgcolour;?>" >
<form action="test1.php" method="POST" name="form1" id="form1" >
<?php echo $select_row_2; ?>
<td width="60" height="25" align="center" valign="middle" class="top-edge-border-menu"><?php echo $row['sub_search_content_id']; ?></td>
<td align="center" valign="middle" class="top-and-right-edge-border-left"><?php echo $row['sub_title']; ?></td>
<td height="25" align="center" valign="middle" class="top-and-right-edge-border">price</td>
<td height="25" align="center" valign="middle" class="top-edge-border"><?php echo $select_row; ?></td>
</form>
</tr>
<?php }
} ?>
</table></td>
</tr>
</tbody>
</table>
<?php mysql_free_result($query1); ?>