Jump to content

Loop is adding too many news feed updates


unemployment

Recommended Posts

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());
	}

	?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.