SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast aweb4u's Avatar
    Join Date
    Jun 2007
    Location
    Auckland, New Zealand
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Coding one to many relationships

    I'm not sure this is the right place to put this in the forums, as it's not just PHP related, but it is to do with application design and I happen to be using PHP so here goes:

    Does anyone have any examples of coding HTML forms for handling one to many relationships?

    For example an invoice is a classic example of a one to many data relationship where the invoice header (client details, invoice date, etc) is on the one side and the invoice detail lines (product being purchased, quantity, cost, etc) are on the many side.

    I know how to set this up on the database side of things, I just haven't found a really good method of handling this in HTML forms that let you easily and quickly add / change / delete invoice detail lines.

    I guess that some AJAX would come in handy here so that there's isn't lots of page refreshing. I've looked at data grids in the past but most of them seem to be set up to display and change lines of data but not to quickly and easily add and delete lines.

    Can anyone point me in the direction of something that might help me out? Any articles or examples?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by aweb4u View Post
    I guess that some AJAX would come in handy here so that there's isn't lots of page refreshing.
    There isn't really a need for Ajax unless you actually need to retrieve additional data from the server.

    For a form where you want to be able to add or remove fields, some ordinary JavaScript can easily add or remove the required fields without a need for ajax.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast aweb4u's Avatar
    Join Date
    Jun 2007
    Location
    Auckland, New Zealand
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    There isn't really a need for Ajax unless you actually need to retrieve additional data from the server.

    For a form where you want to be able to add or remove fields, some ordinary JavaScript can easily add or remove the required fields without a need for ajax.
    I was thinking along the lines of being able to click on a "delete" icon next to a detail line and then the page would remove that line from the DOM and send a request through to the server so a PHP script could delete the record from the database table.

    And the same with adding a detail line, where the user could fill in the fields of a form on the page and when they submitted the form it would update the DOM to show the new detail line and fire off a request to a PHP script which would add the record to the database table.

    And similar for changing existing detail lines.

    The idea is to manipulate the DOM to show updates immediately and send requests to the server in the background so that the page isn't constantly refreshing. Should speed things up nicely!

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    yep, that's ajax. You can do a search in the javascript forum, or google for it. You may write everything in javascript, or use jquery or some other framework.


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
  •