Results 1 to 4 of 4

Thread: [RESOLVED] many $_POST's

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [RESOLVED] many $_POST's

    I have a form (of course) - its built into a table because the user can click a button and add more rows (then fill in more data) - the main issue is the user can remove rows (on the fly) and I want to make the able to move rows up and down (all done with JS)

    fields are
    item_x
    itemdesc_x
    qty_x
    price_x
    total_x

    the x = a number...
    so it could have item_1, item_2, item_3 - but also could have item_1, item_7, item_8 (because they can delete)

    right now, with php I am looping 1 to 10000 and checking if item_X is set then insert into the db. works but its not a good way.


    PHP Code:
    $x 1;
            while (
    $x 10000) {
                if (isset(
    $_POST['item_' $x])){ 
    I know.. BAD BAD BAD (its temporary to make it work)

    How can I loop thought these in the correct order? do they come through the post in top down order? so I might get
    item_7, item_3, item_4, item_9 (if thats how the user arranged them)

    does this make sense? LOL
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: many $_POST's

    use arrays like I suggested you do in the past. it's silly for you to keep track of field indexes when something else can do it for you.

    if the following form is posted to a script:
    HTML Code:
    <form action="post">
      <input type="text" name="name[]" />
      <input type="text" name="name[]" />
      <input type="text" name="name[]" />
      <input type="text" name="name[]" />
      <input type="submit" value="Submit" />
    </form>
    it would produce a $_POST array that might look something like:
    Code:
    Array (
        text[0] => ''
        text[1] => ''
        text[2] => ''
        text[3] => ''
    )
    as far as the HTML goes, you don't need to worry about indexes at all with your javascript stuff. you could then produce a loop like:
    PHP Code:
    <?php

      
    //loop through the text[] field by keys rather than using for()

      
    foreach($_POST['text'] as $key => $value){

        
    //this is -just- the value of $_POST['text'][$key]
        
    echo $value;

        
    //if you have multiple fields for each key, you could then reference them using:
        
    echo $_POST['otherfield'][$key];

      }
    ?>
    this should be easy to adapt to what you might be interested in! if you're not sure how, be more specific about what you want and ask questions.

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: many $_POST's

    but i am using other JS code to calculate the fields of the current row... how can I tell JS which 2 fields to add if I cant hit them with the ID?

    the table needs to have a few functions with it...
    1 onBlur of the qty / price calculate the total + add all totals up to a final total.
    and the rows need to be able to be moved up/down.

    so if i just use the array for the name... the rest should work?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: many $_POST's

    yes, that works! solves the ordering problem thanks!

    now...im just stuck on this http://www.vbforums.com/showthread.php?p=3635170
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width