php - Unset certain items from session array when they're clicked? -


what i'm looking ability remove item array when item clicked, instance... if hit "two", disappear.

demo: http://query.notesquare.me

code:

<form method="post">     <input type="text" id="input-create-playlist" placeholder="playlist name" name="create_playlist" />     <input type="submit" id="button-create-playlist" value="create playlist" /> </form>  <?php     ini_set("session.save_path", "/home/kucerajacob/public_html/query.notesquare.me/test-sessions");     session_start();      if ($_server['request_method'] == 'post') {         $create_playlist = $_post['create_playlist'];          $_session['user_playlists'][] = $create_playlist;     }      $playlists = array("one", "two", "three");      if (isset($_session['user_playlists'])) {         ($i = 0; $i < count($_session['user_playlists']); $i++) {             array_unshift($playlists, $_session['user_playlists'][$i]);         }     }      $_session['main'] = $playlists;      ($i = 0; $i < count($playlists); $i++) {         echo $playlists[$i] . "<br />";     } ?> 

its possible, you'll need handle request well. if want click posted, simple <button> next should suffice.

upon rendering markup, (of course using session array) use key can used in unsetting values.

<?php  // initialization if(empty($_session['user_playlists'])) {     $_session['user_playlists'] = array("one", "two", "three"); }  if(isset($_post['add'], $_post['create_playlist'])) {     // handle additions     $_session['user_playlists'][] = $_post['create_playlist']; }  if(isset($_post['remove'])) {     // handle remove     $key = $_post['remove'];     unset($_session['user_playlists'][$key]); }  ?>  <form method="post">     <input type="text" id="input-create-playlist" placeholder="playlist name" name="create_playlist" />     <input type="submit" id="button-create-playlist" name="add" value="create playlist" />     <hr/>     <?php foreach($_session['user_playlists'] $k => $p): ?>         <?php echo $p; ?>&nbsp;<button type="submit" name="remove" value="<?php echo $k; ?>">remove</button><br/>     <?php endforeach; ?> </form> 

sample demo


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -