Jump to content

Archived

This topic is now archived and is closed to further replies.

Wintergreen

Blog post management question

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

Share this post


Link to post
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]

Share this post


Link to post
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?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.