I’m a huge fan of WordPress’ method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here’s how to achieve that functionality with jQuery JavaScript.
The PHP – Content & Header
The following snippet goes at the top of the page:
if(isset($_GET['delete']))
{
$query = 'DELETE FROM my_table WHERE item_id = '.(int)$_GET['delete'];
$result = mysql_query($query,$link);
}
{
$query = 'DELETE FROM my_table WHERE item_id = '.(int)$_GET['delete'];
$result = mysql_query($query,$link);
}
The following is used to display the records:
$query = 'SELECT * FROM my_table ORDER BY title ASC';
$result = mysql_query($query,$link);
while($row = mysql_fetch_assoc($result))
{
echo '<div class="record" id="record-',$row['item_id'],'">
<a href="?delete=%27,$row[%27item_id%27],%27" class="delete">Delete</a>
<strong>',$row['title'],'</strong>
</div>';
}
$result = mysql_query($query,$link);
while($row = mysql_fetch_assoc($result))
{
echo '<div class="record" id="record-',$row['item_id'],'">
<a href="?delete=%27,$row[%27item_id%27],%27" class="delete">Delete</a>
<strong>',$row['title'],'</strong>
</div>';
}
0 comments:
Post a Comment