Re: Delete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



when you insert each blog into your database, im assuming your not doing
this by hand each and every time, assign each blog an id.

in the place you want to delete the blog entries, list all of the blogs
titles and ids.
and then use mysql(delete);

example:
<?
//create a variable for the delete blog entry of you control panel
    if ($view == delete_blog) {
        //this should be the value of your submit button
        if ($deleteBlog) {
            //this is the value of the blog entries to delete
            if (!$idblog) {
                //this is your error message, to be displayed if no blog was
chosen to delete
                $de = "<font face=tahoma color=black size=1>You Need To
Choose a post to delete</font>";
             }
            else {
                //list the values of the array in which all the blog entries
you would like to delete are
                $delBlog = implode(",", $idblog);
                    //do the actual deletion
                        mysql_query("delete From blogs where id
IN($delBlog)") or die(mysql_error());
                            //display the succesfull message if the blog
entries were deleted
                            echo("<font face=tahoma color=black
size=1><b><center>blog(s):</b> $delBlog <b>has/have been
deleted;</b></b></center>");

//now we display the blog entries
//plus the sucsessfull message
?>

<form method="post">
<?php
$gn = mysql_query("Select * FROM blogs");
while ($d = mysql_fetch_array($gn)) {
?>
<INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
<b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
$d[poster]<b>;</b><br>"); ?>
<?php
 }
?>
<br><br><input type="submit" name="deleteNerd" value="Delete"
class="button">
</form>
<?php
}
}
else {
//display blog entries only
?>
<form method="post">
<?php
$gn = mysql_query("Select * FROM blogs");
while ($d = mysql_fetch_array($gn)) {
?>
<INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
<b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
$d[poster]<b>;</b><br>"); ?>
<?php
 }
?>
<br><br><input type=submit name="deleteNerd" value="Delete" class="button">
</form>
<?php
}
?>
this is a very rough example, however you should catch the drift, make your
id an array, implode that array and delete all the array data from the
database.

----- Original Message ----- 
From: "George Babichev" <geoldr@xxxxxxxxx>
To: "PHP General list" <php-general@xxxxxxxxxxxxx>
Sent: Saturday, June 03, 2006 6:40 PM
Subject:  Delete


> Hello everyone! I wrote a blog application, but now for the admin panel, i
> am trying to add a feature to delete blog posts. It would show the title
of
> the post next to it, and have a delete link which would delete it. How
would
> I do this? I mean if I have multiple blog entry's, how would I delete them
> without using php my admin?
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux