Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default master - detail

    Hello everyone,

    I'm new on this list and have been working for quite a while on a PHP app
    that will make an HTML frontend for a PostgreSQL dbms. Works fine so far
    but I'm having a little trouble with master - detail screens. My db
    (roughly) has a hierarchical structure, something like

    BAND -> RECORD -> SONG

    When I display the record, band should be displayed on top of the screen.
    When song is displayed, band and record should be displayed. (the real app
    has more than 3 layers, but the idea is the same).

    At the moment I use something like storing current band, current record in
    a serialized _SESSION variable. It works, but not very smoothly because
    PHP (or actually HTTP) has no idea of history, descent (the current screen
    doesn't know what the previous screen was).

    So I'm struggling a bit with this. Are there any "standard" solutions for
    this master - detail setup? I found a lot on macromedia, but I don't use
    that, it's just Vim on Linux.

    TIA for any pointers / help!
    Joop Guest

  2. Similar Questions and Discussions

    1. Datagrid Master/Detail
      Hi, I have a Datagrid populated from a Remote Object -Select query- and I looking for a master/detail application to show the details in a...
    2. master detail set php
      I am having problems with the mater detail sets. I create a master detail set and use data from 2 tables linked together with a where clause. But...
    3. Can I delete from the detail of a master/detail datagrid?
      Hi Mark, As for the delte certain items in the detailed grid items in MASTER/DETAIL grids. Here are my suggestions; The DataGrid, DataList or...
    4. Master Detail detail
      Dear gurus, I have got a scenario where I have a master table its detail table its detail table. How to implement this using Data Grid or is...
    5. Master Detail Entry
      How can I make a transactions table type entry using ASP. Say for example in an invoice the no of items ordered may vary invoice to invoice. (The...
  3. #2

    Default Re: master - detail

    Hi Joop,

    I am not completely sure I understand your problem.
    If I don't forget the rest. :-)

    Joop wrote:
    > Hello everyone,
    >
    > I'm new on this list and have been working for quite a while on a PHP app
    > that will make an HTML frontend for a PostgreSQL dbms. Works fine so far
    > but I'm having a little trouble with master - detail screens. My db
    > (roughly) has a hierarchical structure, something like
    >
    > BAND -> RECORD -> SONG
    >
    > When I display the record, band should be displayed on top of the screen.
    > When song is displayed, band and record should be displayed. (the real app
    > has more than 3 layers, but the idea is the same).
    >
    > At the moment I use something like storing current band, current record in
    > a serialized _SESSION variable. It works, but not very smoothly because
    > PHP (or actually HTTP) has no idea of history, descent (the current screen
    > doesn't know what the previous screen was).
    >
    > So I'm struggling a bit with this. Are there any "standard" solutions for
    > this master - detail setup? I found a lot on macromedia, but I don't use
    > that, it's just Vim on Linux.
    Nothing 'standard' about it. Just normal relations in your database, so just
    'good programming practice'.

    Let me explain:
    You have a certain depth in your structure, right?
    And I guess you have certain PHP-scripts that display information on a band,
    or a record, song, etc. Right?

    In that case I do not see the problem retrieving the information in the
    hierarchy.

    Let's take your example: BAND -> RECORD -> SONG

    Supose you call a page showSongDetails.php?songid=456

    where the songid in your db is 456

    If your database is set up in a comprehensive way, the table that stores
    songid (lets call it tblsong), also stores a reference (foreign key) to
    your recordtable (tblrecord).

    Same goes for tblrecord to tblband.

    In that way you can say for every song, of which band it is, simply by:
    SELECT bandid, bandname, etc etc FROM tblband WHERE
    (bandid=(SELECT bandid FROM tblsong WHERE songid=$songid));

    in which $songid must of course be replaced by 456

    Hope that helps.

    Good luck,
    Erwin
    >
    > TIA for any pointers / help!
    Erwin Moller Guest

  4. #3

    Default Re: master - detail

    On Tue, 02 Sep 2003 14:16:27 +0200, Erwin Moller wrote:
    > Hi Joop,
    >
    > I am not completely sure I understand your problem. If I don't forget
    > the rest. :-)
    No, you understood it perfectly but I oversimplified the question, let me
    try again.

    <big snip>
    > In that way you can say for every song, of which band it is, simply by:
    > SELECT bandid, bandname, etc etc FROM tblband WHERE
    > (bandid=(SELECT bandid FROM tblsong WHERE songid=$songid));
    I only used the band -> record -> song setup as an example and a bad one,
    sorry. Here's a better one (almost the real situation).

    I have these tables

    customer (key customer-id)
    employee (foreign keys customer-id and person-id)
    person (key person-id)

    the relations are:

    customer >-<< employee >>-< person

    so a customer can have 0 or more employees and a person can be 0 or more
    employees (can have 0 or more jobs). There's more, an employee can call in
    sick 0 ore more times and a doctor can store 0 or more medical records on
    a person, but the core is cust / emp / person.

    In my PHP app, there are two routes that lead to employee, via customer
    and via person. When coming from customer the screen should have customer
    + employee fields, when coming from person it should have person +
    employee fields. So my app has to determin where it's coming from, and
    that information table is not in a table. That's why I use session
    variables now, but the nature of HTTP (stateless) and browsers make this
    difficult to handle.

    Hope this is a bit more clear. Has anybody else done this kind of thing in
    PHP? TIA!
    Joop Guest

  5. #4

    Default Re: master - detail

    Joop wrote:

    Hi Joop,

    (Ben jij nederlands? / Are you Dutch?)
    I am. :-)
    > On Tue, 02 Sep 2003 14:16:27 +0200, Erwin Moller wrote:
    >
    >> Hi Joop,
    >>
    >> I am not completely sure I understand your problem. If I don't forget
    >> the rest. :-)
    >
    > No, you understood it perfectly but I oversimplified the question, let me
    > try again.
    >
    > <big snip>
    >
    >> In that way you can say for every song, of which band it is, simply by:
    >> SELECT bandid, bandname, etc etc FROM tblband WHERE
    >> (bandid=(SELECT bandid FROM tblsong WHERE songid=$songid));
    >
    > I only used the band -> record -> song setup as an example and a bad one,
    > sorry. Here's a better one (almost the real situation).
    >
    > I have these tables
    >
    > customer (key customer-id)
    > employee (foreign keys customer-id and person-id)
    > person (key person-id)
    >
    > the relations are:
    >
    > customer >-<< employee >>-< person
    >
    > so a customer can have 0 or more employees and a person can be 0 or more
    > employees (can have 0 or more jobs). There's more, an employee can call in
    > sick 0 ore more times and a doctor can store 0 or more medical records on
    > a person, but the core is cust / emp / person.
    Okay, that is clear.
    >
    > In my PHP app, there are two routes that lead to employee, via customer
    > and via person. When coming from customer the screen should have customer
    > + employee fields, when coming from person it should have person +
    > employee fields. So my app has to determin where it's coming from, and
    > that information table is not in a table. That's why I use session
    > variables now, but the nature of HTTP (stateless) and browsers make this
    > difficult to handle.
    >
    You can handle this in 2 'main' ways.
    But I guess you figured that out yourself already. :-)
    Maybe it help you when somebody else comments on it.

    Let me clarify:

    1) Just create 2 PHP-pages.
    One for the route from customer (cust_empl.php),
    One for the route from person (pers_empl.php).

    This has the big advantage that you logically devide the routes and have the
    possibility to do extra graphics/information/etc depending on the route.
    I can imagine that you have to create more info depending on the route in
    the future. In this way things are implemented easier/cleaner than with
    if/then/else constructs of course.

    And if a big chunk of the data is the same: Just make an include of it
    (empl_view_incl.php) and keep the (breadcrumps??) logic out of it and in
    the separate files (=cust_empl.php and pers_empl.php).



    2) Store the state in _SESSION as you described and use already.

    The fact that HTTP-protocol is stateless is excactly WHY sessiondata is
    invented in the first place.
    You use probably the _SESSION-array already to store other information I
    guess???

    So nothing wrong with your current approach I think.
    I would advise you to stick to it unless one of the reasons in 1) is
    compelling enough to switch.


    > Hope this is a bit more clear. Has anybody else done this kind of thing in
    > PHP? TIA!
    Hope this helps.
    I am sure you can find literature for both approaches if you look for it.
    I have done a lot of coding like this and have a very pragmatic approach:
    Sit back, think it over, and pick whatever solution makes the most sense to
    you.


    Regards and good luck,
    Erwin
    Erwin Moller Guest

Posting Permissions

  • You may not post new threads
  • You may 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