Jump to content


Blog post management question

  • Please log in to reply
3 replies to this topic

#1 Wintergreen

  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 06 September 2006 - 12:18 PM

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

#2 redarrow

  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 September 2006 - 12:40 PM

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.

//database connection

$query="select * from post";



echo $record['description'];

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




$del="delete from post where description='".$record['description']."'";

<input type="submit" name="submit" value="delete">

Wish i new all about php DAM i will have to learn

#3 Wintergreen

  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 06 September 2006 - 01:29 PM

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:

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

My question now is will the $_POST['post$i'] part work?

#4 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 September 2006 - 01:43 PM

try something like
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>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users