php - How to store field Id in a row? -


I write a web site with jquery and many AJAX requests that get data for the table and PHP / Ask the data modifications on MySql Server Side

Currently, I use the ID attribute to store the field ID of the table (which is an exchanged int value). And it works fine.

But I have recently learned that the ID should be unique (and start with a letter ...). And I have different tables that can have the same ID value. (For different sql table) I'm not homologous (and xHTML) ...

How can I correct my code?

  • Using jQuery function?
  • A hidden HTML element with ID ( & lt; span class = "id"> 3 )?
  • Other solutions?

    Additional Notes:
    I have written a widget to manage my tables.
    To add a new line, I do:

      line = $ ('

    when field elements When I change, an event in the table that asks to modify the server with the correct ID:

      $ (e.target) .closest (".line") Attr ("id")    

    If you use html 5 data A Are able to or can see more than - * attributes JQuery 1.4.3 will automatically use those data-attributes and put them in the archive on the .data () element

    Example:

      & lt; Table & gt; & lt; tr data-lineid = "1" & gt; & lt; / tr & gt;  will print  1   

    $ ("tr: first"). Code>

    This method will also allow you to store JSN objects.

      & lt; Table & gt; & Lt; Tr data-line = '{"id": 1, "name": "smith"}' & gt; & Lt; / TR & gt; & Lt; / Table & gt;   

    and more than your data () var line = $ ("tr: first"). You can refer to the data ("line") you row.id and row.Name

Comments