How to delete the item from table? I am using SESSION.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aveeva
    New Member
    • Apr 2019
    • 33

    How to delete the item from table? I am using SESSION.

    Here is my code :

    Code:
    <html> 
    <head> 
    
        <style type="text/css"> 
            table { 
                border-collapse: collapse; 
                border: 1px solid black; 
            } 
            table td,th { 
                border: 1px solid black; 
            } 
            td { 
                text-align: center; 
            } 
        </style> 
    </head> 
    
    <body> 
    
        <h2>Play Lists</h2> 
    
        <table> 
            <th>Voice SKU</th> 
            <th>Voice Name</th> 
            <th>Action</th> 
         
    
            <?php 
           session_start(); 
          foreach ($_SESSION['playlist'] as $key => $value) { 
            echo "<tr>"; 
            echo "<td>" . $key . "</td>\n<td>" . $value . "</td>"; 
    
            echo "<td>". "<button id='btn'>Delete</button>"."</td>"; 
    
            echo "</tr>";     
            } 
            ?> 
        </table> 
    </body> 
    </html>
    output:

  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    You could do this by creating a javascript function for each button

    change line #34 to:
    Code:
    echo '<td><button onclick=' . 'alert("' . $key . '")' . ' id="btn">Delete</button></td>';
    Sorry for changing the doublequotes to singlequotes, and vice versa, but … 😉

    With this code you should see a popup window with the value of $key.

    In stead of 'alert', you could create another javascript function that send i.e. 'http://localhost/delete?id=...' to you server, which then deletes the key from the SESSION on the server.
    (But this part (SESSIONs) is not really known to /me, … )

    Comment

    • aveeva
      New Member
      • Apr 2019
      • 33

      #3
      Thanks for your help.

      Comment

      Working...