Professional Web Applications Themes

How to have unique id's for POSTing when displaying many table rows? - PHP Development

How to deal with multiple records and posting values? (I'm fairly new to html/php etc. so maybe there is a simple answer? I have a page showing several records - each table record is contained within a separate form and has action buttons that submit (for update/delete etc). I generate the html using a php loop, which adds the loop counter to inputs name and id (to ensure unique id's). This results in the $_POST array receiving results as "budgetname1", or "budgetname2" etc. Do I have to p the POST array, when what i really want is just "budgetname" in ...

  1. #1

    Default How to have unique id's for POSTing when displaying many table rows?

    How to deal with multiple records and posting values?
    (I'm fairly new to html/php etc. so maybe there is a simple answer?

    I have a page showing several records - each table record is contained
    within a separate form and has action buttons that submit (for
    update/delete etc).

    I generate the html using a php loop, which adds the loop counter to
    inputs name and id (to ensure unique id's).
    This results in the $_POST array receiving results as "budgetname1", or
    "budgetname2" etc.

    Do I have to p the POST array, when what i really want is just
    "budgetname" in the POST array, no matter which record the user clicks
    on (the values tell me what i need!).
    Although the page works if I assign the same id's in each form, the HTML
    spec seems to suggest that a) id's must be unique in the doent, b)
    that name and id must be the same, and c) that "[]" characters are not
    permitted in HTML 4.01

    So do I have to step thru the POST array checking all the keys looking
    for a substring match of the key to "budgetname%" or similar??

    I guess this must be a common problem with multi-row tables on a page,
    but what's the best solution?
    thanks
    chris
    Second_Chance Guest

  2. #2

    Default Re: How to have unique id's for POSTing when displaying many table rows?

    Second_Chance wrote: 
    contained 
    or 
    clicks 
    HTML 

    id attributes of HTML controls don't affect the POST variable name,
    only the name attribute. So just make all the name attributes the same.
     

    Where does it say that??
     

    And where does it say that?
    Using [0], [1], [2], etc. is the recommended way of getting an array as
    a POST variable in PHP.

    --
    Oli

    Oli Guest

  3. #3

    Default Re: How to have unique id's for POSTing when displaying many tablerows?

    Oli Filth wrote:
     
    >
    > contained

    >
    > or

    >
    > clicks

    >
    > HTML

    >
    >
    > id attributes of HTML controls don't affect the POST variable name,
    > only the name attribute. So just make all the name attributes the same.
    >

    >
    >
    > Where does it say that??

    >
    > And where does it say that?
    > Using [0], [1], [2], etc. is the recommended way of getting an array as
    > a POST variable in PHP.
    >[/ref]

    Oli, thanks for reply..

    re c) I read the following at:

    http://www.w3.org/TR/html4/types.html#type-id
    "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
    followed by any number of letters, digits ([0-9]), hyphens ("-"),
    underscores ("_"), colons (":"), and periods ("."). "

    from which I assume [] are not ok

    re b) that name and id must be the same

    I can't find the section, think was in the same spec.. and said that if
    both name and id attributes are set they should be the same (and name
    was now deprecated..)
    the last bit is here:
    from this page:

    www.w3.org/TR/html4/interact/forms/html#h-17.1

    name = cdata [CI]
    This attribute names the element so that it may be referred to from
    style sheets or scripts. Note. This attribute has been included for
    backwards compatibility. Applications should use the id attribute to
    identify elements.

    However, I am quite new at this, so will follow your suggestions
    many thanks
    Chris

    Second_Chance Guest

  4. #4

    Default Re: How to have unique id's for POSTing when displaying many table rows?

    Second_Chance wrote: 
    <...SNIP...>
     

    Hmm, you're absolutely right, it does say that, I'd never noticed that
    before! Which is bizarre, cos the HTML validator has never complained!
     
    if 
     

    That's referring to the name attribute for the <FORM> element, not the
    individual <INPUT>, <TEXTAREA> and <SELECT> controls within it.

    --
    Oli

    Oli Guest

Similar Threads

  1. Question Remove Duplicate Rows in MySQL Table Having No Primary Key or Unique Index
    By deltaforce in forum Brainstorming Area
    Replies: 0
    Last Post: July 25th, 10:14 AM
  2. Replies: 3
    Last Post: September 20th, 12:38 PM
  3. creating unique rows
    By VB.NET in forum MySQL
    Replies: 4
    Last Post: February 19th, 10:24 PM
  4. Replies: 0
    Last Post: September 16th, 04:37 PM
  5. Replies: 0
    Last Post: September 10th, 05:29 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139