Creating Master-Detail or Parent-Child Form in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rehanqadri
Forum Newbie
Posts: 2
Joined: Fri Jul 31, 2009 11:21 am

Creating Master-Detail or Parent-Child Form in PHP

Post by rehanqadri »

I have been working on PHP for quite sometime but recently I have been faced with a situation in which I have to create a MASTER DETAIL form having CRUD operations [Create, Read, Update and Delete]. In PHP, i have never done this and looking for some sample code in order to achieve this.

Let me give an example what I want to achieve:

Master Information: [Voucher_Master]
===============
Transaction Number:
Voucher Date:
Voucher Description:

Detail Information: [Voucher_Detail]
==============
Account Code Account Name Debit Credit

There is one to many relationship between Voucher_Master and Voucher_Detail.

I would be very thankful if somebody can guide me in this regard.

Eagerly waiting for response.
DaiLaughing
Forum Commoner
Posts: 76
Joined: Thu Jul 16, 2009 8:03 am

Re: Creating Master-Detail or Parent-Child Form in PHP

Post by DaiLaughing »

Bear in mind I'm only answering this because no one else has!

Personally I have done this a couple of years ago using just one form. The one side of the relationship is populated with a query. Then the many fields of the form are populated with a loop using data from another query. The way I handled the repeated data was just to rename the fields with the primary key after the field name. So you would end up with Detail_Information1, Detail_Information2 o whatever the fields were. When the form was posted I then stripped the ID back off of the end of the field name and saved the data in the related "many" table.

Ugly but it worked. I believe the correct way would be to create the form with a loop as I did but give the fields in the repeated area a single name but with square brackets after the name. Then the repeated fields would be stored in $_POST but in their own array. Then you can more easily FOREACH through the results. I have never goteen around to trying it on a proper page but it should work better than my kludge.
rehanqadri
Forum Newbie
Posts: 2
Joined: Fri Jul 31, 2009 11:21 am

Re: Creating Master-Detail or Parent-Child Form in PHP

Post by rehanqadri »

thanks mate, i will surely try it out and will late you know about the progress and issues.

thanks again
Post Reply