By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,589 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,589 IT Pros & Developers. It's quick & easy.

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

aveeva
P: 28
Here is my code :

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head> 
  3.  
  4.     <style type="text/css"> 
  5.         table { 
  6.             border-collapse: collapse; 
  7.             border: 1px solid black; 
  8.         } 
  9.         table td,th { 
  10.             border: 1px solid black; 
  11.         } 
  12.         td { 
  13.             text-align: center; 
  14.         } 
  15.     </style> 
  16. </head> 
  17.  
  18. <body> 
  19.  
  20.     <h2>Play Lists</h2> 
  21.  
  22.     <table> 
  23.         <th>Voice SKU</th> 
  24.         <th>Voice Name</th> 
  25.         <th>Action</th> 
  26.  
  27.  
  28.         <?php 
  29.        session_start(); 
  30.       foreach ($_SESSION['playlist'] as $key => $value) { 
  31.         echo "<tr>"; 
  32.         echo "<td>" . $key . "</td>\n<td>" . $value . "</td>"; 
  33.  
  34.         echo "<td>". "<button id='btn'>Delete</button>"."</td>"; 
  35.  
  36.         echo "</tr>";     
  37.         } 
  38.         ?> 
  39.     </table> 
  40. </body> 
  41. </html>
  42.  
output:

https://snag.gy/vOt9VX.jpg
Jul 18 '19 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,035
You could do this by creating a javascript function for each button

change line #34 to:
Expand|Select|Wrap|Line Numbers
  1. 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, )
Jul 20 '19 #2

aveeva
P: 28
Thanks for your help.
4 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.