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

	?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.