HLP foreach multiple inputs form Howto loop array of inputs... ?

Discussion in 'PHP' started by fdoze, Nov 13, 2008.

  1. #1
    Hi,

    I have a form that creates dynamic newsletter items.


    I have thie newsletter basic info:
    
    <input type="text" id="id_title" class="vTextField required" name="title" size="30" value="newsletter" maxlength="200" />
    
    Code (markup):
    When I add Item it creates:
    
    <input type="text" id="id_title" class="vTextField required" name="item_title[]" size="30" value="Titulo" maxlength="200" />
    
    <input type="file" id="id_image" class="vTextField required" name="item_image[]" size="30" value="" maxlength="200" />
    
    <textarea name="item_text[]" rows="10" cols="60" class="mceSimple">Texto</textarea>
    
    
    Code (markup):

    I need to Insert/Update a Newsletter info into Newsletter Table and to Insert News Items into Newsitems Table.

    I am unable to get each new item so I can insert/update on my while under the form Requests...

    Could you please help me?

    When I do this:
    
    foreach ($_REQUEST['item_title'] as $value) {
    						
     echo key($_REQUEST['item_title']); echo "--".$value."-";
     echo $_REQUEST['item_title'][key($value)];
    			}	
    
    PHP:
    I get allways the value 0 for array key under item_tile...

    How can I do a WHILE/FOR Loop under all the group of items that I have created??

    Please help me.



    Many thanks in advance!!
     
    fdoze, Nov 13, 2008 IP
  2. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try

    foreach ($_POST['item_title'] as $value1) {
    foreach ($value1 as $value2) {
    //Do database work with $value2
    echo $value2;
    }
    }

    And add a foreach for each different element.
     
    atlantaazfinest, Nov 13, 2008 IP
  3. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    each element is a filed from a table...

    I have to Insert the firt item, then get last_insert_id() and finaly do UPDATE For every item left.. Correct?
     
    fdoze, Nov 13, 2008 IP
  4. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I got

    Warning: Invalid argument supplied for foreach()
     
    fdoze, Nov 13, 2008 IP
  5. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    GOT IT!

    Like this:

    foreach($_REQUEST['item_title'] as $k => $item_title)


    Nice?
     
    fdoze, Nov 13, 2008 IP
  6. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There you go you got it!
     
    atlantaazfinest, Nov 13, 2008 IP
  7. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yap. Many thanks anyway.
     
    fdoze, Nov 14, 2008 IP