Jump to content


Photo

Blog post management question


  • Please log in to reply
3 replies to this topic

#1 Wintergreen

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

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.
<?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>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Wintergreen

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

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

Posted 06 September 2006 - 01:43 PM

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

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






moon.png

|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