Results 1 to 3 of 3
  1. #1

    PHP: Nested foreach statements giving me problems

    Ok, this is going to be hard to explain but I'll try,

    I have a page where an admin can modify member ranks, It lists the members and then next to the name there is a drop down menu for each member with some ranks: Admin, Member, Moderator etc.

    Now, I have a hidden field member_id[] and the drop menu has the name rank[]. When the form is submitted I have:

    PHP Code:
    foreach ($_POST[member_id] as $member_id) {

        foreach (
    $_POST[rank] as $rank) {

    Then here is where I update the mysql database with the values


    But I keep getting double results and it then it only changes the last members information. I kinda solved the problem with array_combine in PHP5 but if the two variable's values are the same it returns an error, so I am looking for an alternative. Thanks.

  2. #2
    Join Date
    Nov 2002
    try something like this..

    PHP Code:
    <input type="hidden" name="member[id][]" value="xxxxxx">
    select name="member[rank][]">
    option value="admin">admin</option>
    option value="moder">moder</option>
    option value="...">...</option>
    and PHP:
    PHP Code:
    foreach ($_POST['member']['id'] as $key => $Value)
    mysql_query("UPDATE table_name SET rank = $_POST['member']['rank'][$key] WHERE userID = $Value LIMIT 1;");

    NOT tested, but hope this helps you out..

    -- t3r0

  3. #3
    Join Date
    Mar 2003
    a fast get around....Can this work???

    PHP Code:
    foreach (
    $_POST[member_id] as $member_id) { 
    //populate using $member_id and $_POST['rank'][$i]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts