Jump to content

PHP update foreach array error


Monkuar

Recommended Posts

//Update the ranks
if (isset($_POST['update'])){
$ids = implode(",", array_map('intval', $_POST['m']));
$ranks = implode(",", array_map('intval', $_POST['ranks']));
if ($ids < 1)
message("Incorrect Data");
if ($ranks < 0)
message("Incorrect Data");
foreach ($_POST['ranks'] as $muffins){
$db->query('UPDATE friends set rank = '.$muffins.' WHERE friend_id = '.$_POST['m'].' AND user_id = '.$pun_user['id'].'') or error('Unable to remove users from online list', __FILE__, __LINE__, $db->error());
}
redirect("s.php?section=Friends","Thanks, Ranks Updated");
}

 

friend_id = becomes blank? the $muffins work and each rank is showed respectivaly, but how can I join in another array in the loop? I tried another foreach in the loop, but it just made me run double the queries.

 

Any idea? $muffins is working fine and $_POST['m'] is giving no results  i need to have 2 dynamic arrays in that forloop, the $ranks and the $ids

Link to comment
Share on other sites

fixed it

foreach($_POST['ranks'] as $index=>$value)
{
$ranks = mysql_real_escape_string(TRIM($_POST['ranks'][$index])); 
	$ids = mysql_real_escape_string(TRIM($_POST['m'][$index])); 

$db->query('UPDATE friends set rank = '.$ranks.' WHERE friend_id = '.$ids.' AND user_id = '.$pun_user['id'].'') or error('Unable to remove users from online list', __FILE__, __LINE__, $db->error());
}
redirect("s.php?section=Friends","Thanks, Ranks Updated");
}

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.