JPark Posted November 18, 2009 Share Posted November 18, 2009 I have an intranet page where people can make comments or suggestions. The powers-that-be would like to review the comments before they are posted on the web page. Right now, I have a form that the 'customer' can fill out. When they hit submit, their name, e-mail and comments get posted to a mysql database and the powers-that-be get an e-mail notification. I would like them to be able to go to an approval page and see all (or one at a time) the posts that are pending approval and be given a choice to approve or delete each comment. I would like to keep it all on one page and, each time a comment is approved or deleted, the page is refreshed with the next comment to approve/delete. Is that an option with php? I know I can query one row at at a time with mysql_fetch_array, but I can't seem to get past the first row. On the other hand, if I display all the comments, the page doesn't refresh right. I will continue to see the comments that have already been deleted or F5 will attempt the same query. This is what I am am working with... $query = 'SELECT * FROM `comments` WHERE `approved` = 1'; //1 = new, 2 = approved $result=mysql_query($query) or die(mysql_error() ); while($row = mysql_fetch_array($result)){ echo $row['name']. " - ". $row['email']; $id = $row['id']; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="test"> <input name="decision" type="radio" value="approve" /> Approve this comment<br /><input name='id' type='hidden' value='<?php echo $row['id']; ?>' /> <input name="decision" type="radio" value="delete" /> Delete this comment<br /> <input name="Submit" type="submit" /> <input name="Reset" type="reset" value="Reset" /> </form> <?php if ($_POST['decision'] == 'delete') { mysql_query("DELETE FROM comments WHERE id = '$id'"); echo $row['id']."<br />"; } } Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/182038-solved-comment-board-admin-page/ Share on other sites More sharing options...
MadTechie Posted November 18, 2009 Share Posted November 18, 2009 I would probably code it like this (untested) <?php //check a decision has been posted if(!empty($_POST['decision'])){ //loop thought the decision's foreach($_POST['decision'] as $ID => $decision){ $ID = (int)$ID; //Apply decisions switch($decision){ case "delete": mysql_query("DELETE FROM comments WHERE id = '$ID'"); break; case "approve": mysql_query("UPDATE comments SET approved=2 WHERE id = '$ID'"); break; } } } $query = 'SELECT * FROM `comments` WHERE `approved` = 1'; //1 = new, 2 = approved $result=mysql_query($query) or die(mysql_error() ); ?> <form action="" method="post" name="test"> <?php while($row = mysql_fetch_array($result)){ echo $row['name']. " - ". $row['email']; $id = $row['id']; ?> <input name="decision[<?php echo $row['id']; ?>]" type="radio" value="approve" /> Approve this comment<br /> <input name="decision[<?php echo $row['id']; ?>]" type="radio" value="delete" /> Delete this comment<br /> <?php } ?> <input name="Submit" type="submit" /> <input name="Reset" type="reset" value="Reset" /> </form> Hope that helps, any questions ? Quote Link to comment https://forums.phpfreaks.com/topic/182038-solved-comment-board-admin-page/#findComment-960239 Share on other sites More sharing options...
JPark Posted November 18, 2009 Author Share Posted November 18, 2009 That works great! I appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/182038-solved-comment-board-admin-page/#findComment-960262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.