unemployment Posted April 27, 2011 Share Posted April 27, 2011 When a post is approved I only want $details = $_POST['newstitle']; update_user_actions(8, $details); Being posted once with the corresponding news article title. Any way to achieve this? Right now it is looping through all of the titles and is posting them all. foreach($posts as $post) { $displayName = ucwords("${post['firstname']} ${post['lastname']}"); if (isset($_POST['approve'])) { if(is_array($_POST['approve'])) { $keys = array_keys($_POST['approve']); $id = $keys[0]; $details = $_POST['newstitle']; update_user_actions(8, $details); $sql = "UPDATE `news` SET `newsdate` = NOW(), `approved` = 1 WHERE `id` = '$id'"; header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ); } } else if (isset($_POST['deny'])) { if(is_array($_POST['deny'])) { $keys = array_keys($_POST['deny']); $id = $keys[0]; $sql = "UPDATE `news` SET `newsdate` = NOW(), `approved` = -1 WHERE `id` = '$id'"; header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ); } } else if (isset($_POST['delete'])) { if(is_array($_POST['delete'])) { $keys = array_keys($_POST['delete']); $id = $keys[0]; $sql = "DELETE FROM `news` WHERE `id` = '$id'"; header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ); } } if(isset($sql) && !empty($sql)) { mysql_query($sql) or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234895-loop-is-adding-too-many-news-feed-updates/ Share on other sites More sharing options...
gizmola Posted April 27, 2011 Share Posted April 27, 2011 Well of course, you have only one variable you are checking $_POST['approve'], and I assume this form has a table or list of posts. You would need some sort of scheme in the form, so that you can tell which post out of many has been approved, denied, deleted etc. Quote Link to comment https://forums.phpfreaks.com/topic/234895-loop-is-adding-too-many-news-feed-updates/#findComment-1207155 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.