Re: Delete
| From: | George Babichev | Date: | Sun, 04 Jun 2006 05:53:45 +0000 |
| Subject: | Re: Delete | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237337@lists.php.net to get a copy of this message | ||
Thank you for the help guys, but the I guess I kinda have another question.
So I do assign an id to each blog post, and it is auto_increment, so in my
blog delete page, it would display all the blog title's and a delete button
nex to it. So lets say I click delete on the third entry. How would my
program know to delete THAT entry and not another one?
On 6/3/06, benifactor <snorris17@cox.net> wrote:
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 panelif ($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 blogwas chosen to delete$de = "<font face=tahoma color=black size=1>You Need ToChoose a post to delete</font>";} else { //list the values of the array in which all the blogentries you would like to delete are$delBlog = implode(",", $idblog); //do the actual deletion mysql_query("delete From blogs where idIN($delBlog)") or die(mysql_error());//display the succesfull message if the blogentries were deletedecho("<font face=tahoma color=blacksize=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@gmail.com> To: "PHP General list" <php-general@lists.php.net> Sent: Saturday, June 03, 2006 6:40 PM Subject: [PHP] 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?