Jump to content

Blog post management question


Wintergreen

Recommended Posts

I have a blog set up now, but I'd like to make an easy way of managing the posts (easier than manually through SSH).  The easiest way would be to include a form checkbox on the edit page (the edit page shows one post at a time) and go from there, however I'd like to list all posts with checkboxes by them and be able to select multiple posts to get rid of at a time. 

My problem with setting this up, though, is that I'm not sure how to pass all the post IDs of the selected posts through to the page that will actually delete them.  Each time I've made an edit page or a comment page it always passes in the postid using $_GET, but that won't work in this case because I don't know how many or which posts will be selected for deletion.

Any help would be great
Link to comment
Share on other sites

i am not sure if somethink like this even works but i come up with this.

example only not tested dont no even this is correct sorry.
[code]
<?php

//database connection

$query="select * from post";

$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

echo $record['description'];


?>
<form method="POST" action"">
<br>
delete post
<br>
<input type="radio" name="yes">click for yes.......
<br>

<?php
}

if(isset($_POST['submit'])){

if($record['description']=="yes"){

$del="delete from post where description='".$record['description']."'";
$del_res=mysql_quey($del);

}
}
?>
<input type="submit" name="submit" value="delete">
</form>

[/code]
Link to comment
Share on other sites

I was thinking, I can do a read of the number of rows that fit the search criteria, and then pass that into the page that deletes the posts.  I would have the name of the checkboxes go up one per post, so the first would be post0, second would be post1, etc.  So I could do:

[code]
for ($i = 0; $i <= $postcount; $i++) {
  if ($_POST['post$i']) {
    blah blah
  }
}
[/code]

My question now is will the $_POST['post$i'] part work?
Link to comment
Share on other sites

try something like
[code]<?php
include 'db2.php';
if (isset($_POST['submit'])) {
    $idlist = join (',', $_POST['delbox']);
   
    mysql_query ("DELETE FROM mytable WHERE id IN ($idlist) ");
}


$sql = "SELECT id, description FROM mytable";
$res = mysql_query($res) or die(mysql_error());
echo '<FORM method="POST">';
while (list ($id, $desc) = mysql_fetch_row($res)) {
    echo "<input type='checkbox' name='delbox[]' value='$id'> ";
    echo "$desc<br>" ;
}
echo "<input type='submit' name='submit' value='Delete selection'>";
echo '</FORM>';
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.