Jump to content

Recommended Posts

Ok here we go...

 

 

 

What I have here is three select boxes one for all the tables in the db, one listing the table columns in that table and a third to collect the table columns selected stored in a session called $_SESSION['collections'].  Up to this point all that works beautiful the session stores the selected collections.

 

But heres what I want to be able to do: I want to remove single values from the $_SESSION['collections'].  How do I do that?

 

 

Currently it posts the value I want to remove just as it collects the values in the collections select box.  But how do I remove that single element from the array?

 

//----------------------DATABASE ABOVE THIS LINE----------------//


	// Sesssion Start and Session Counter
	session_start();
	$counter = $_SESSION['counter']++; 
	// ----------------------------//


	//-Get Database Table--//
	if($_GET['table']) {
	$tables = $_GET['table'];
	}
	else {
	$tables = 'project';
	}
	$query = 'select * from '. $tables;
	$result = mysql_query($query, $link);
	///---------------//

	//Store Session Collection Values
	if($_GET['collections']){
	$_SESSION['collections'][$counter] = $_GET['collections'];
	}



	$sql1 = "SHOW TABLES FROM $dbname";
	$result1 = mysql_query($sql1);


//------------------tables------------------------//
	echo '<table>';
	echo '<tr>';

	echo '<td valign="top">';		
	echo '<form method="GET" action="">';


	print '<select multiple  name="table" onBlur="window.location.href=\'testing.php?table=\' + this.value">';
		while ($row = mysql_fetch_array($result1)) {
			for($i=0;$i<mysql_num_fields($result1);$i++) {
			  }    
			print  '<OPTION VALUE='.$row[mysql_field_name($result1, $i)].'>'.$row[mysql_field_name($result1, $i)].''; 
			  }	
	echo '</select>'; 
//-----------------------------------------------//

//--------------------tableheadings---------------------------//
	echo '</td>';
	echo '<td valign="top">';

		print '<select multiple name ="collections" onBlur="window.location.href=\'testing.php?collections=\' + this.value"" >';
	for ($i = 0; $i < mysql_num_fields($result); $i++) { 
    	
	print  '<OPTION VALUE='.mysql_field_name($result, $i).'>'.mysql_field_name($result, $i).''; 
		} 
	echo '</select>';
	echo '</td>';

//------------------collections------------------//
	echo '<td valign="top">';
	print '<select multiple  name="collections" onBlur="window.location.href=\'testing.php?unset=\' + this.value"" >';
	foreach($_SESSION['collections'] as $key => $value) {
	print  '<OPTION VALUE='. $value .'>'. $value .'';

		   }
	echo '</select>';
	echo '</form>';
	echo '</td>';
	echo '</tr>';
	echo '</table>';
//-----------unsetting-----------------

	if($_GET['unset']){
	unset($_SESSION['COLLECTIONS'][$unset]);
	}


?>

 

Have you tried replacing the unset($_SESSION['COLLECTIONS'][$unset]); with unset($_SESSION['collections'][$_GET['unset']]);

 

The $unset you are trying to use there currently is not defined anywhere, as MmmVomit said. In addition, do note that those array keys are case sensitive. You were trying to use upper case in this particular piece, while rest of the code uses lower case.

Tried it no change

 

unset($_SESSION['collections'][$_GET['unset']]);

 

Theoretically it should work.. or at least I think so :)

 

unset($_SESSION['collections'][$_GET['unset']]); realy = unset($_SESSION['collections']['value_in_collection']];

 

seems logical.... but nada!

Hmm.. perhaps you have error in the following line

 

print  '<OPTION VALUE='. $value .'>'. $value .'';

 

Perhaps this should rather be:

 

print  '<OPTION VALUE='. $key .'>'. $value .'';

 

If you are using the $value as the value, instead of the $key, then only the value of the session variable is sent to the unset (assuming the script works as I expect it to). However, then you are trying to unset the session variable by the value, rather than the key, which obviously wont work (unless they are the same).

 

If this is not the case, however, I would recommend putting var_dump($_GET); before the unsetting if clause to make sure that the correct variable exists and has value you expect it to have.

Spoke too soon

 

 

Almost solution.

 

             if($_GET['unset']){

unset($_SESSION['collections'][$key]);

header('location: http://cesserver5/testing.php');

}

It unsets the correct values unless you select the top one first.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.