Family and Familymembers

brononius 07 Feb, 2014
Hey,

I've trying to create a kind of site for families.
My idea is that somebody creates a family (fe janssens) and his familymembers (fe Jan, Els, Piet).
No I would like to have 2 tables (fe family & members).
And they should look like:

Table 1: Family
ID Family
01 Janssens

Table 2: Members
ID Member Family
01 Jan 01
02 Els 01
03 Piet 01


So I would like to have the ID of family in Table 1 been used in Table 2. Is this possible with 1 form?
For the moment, I can't figure out how I could find out what the ID will be that I should use in Table2.
GreyHead 07 Feb, 2014
Hi brononius,

Yes, you can do this but you have to hand-code the database save for at least the second table, and it might be simplest to do both at the same time. Save the family first, get the record id of the new record and add that to the member saves.

You could use a DB Save action for the family save, ChronoForms adds the cf_id of the new record into the $form->data array so you can get that and use it in the code for the remaining saves.

Bob
brononius 07 Feb, 2014
Okay, so far so good (to view it):

I've create some forms, i've create some extra tables (TB_data_family & TB_data_familymembers). And when I add in my form follow code (in the block on submit), I've got nicely the ID's I want:

<?php
$result = mysql_query("SELECT `id` FROM `TB_users` WHERE `username`='" . $form->data['username'] . "'");  
while($row = mysql_fetch_array($result))
   {
$id = $row['id'];
echo "<input type='hidden' name='familymember' id='familymember' value='" . $id ."'> ";
echo "<h2>Familymember ID test:  " . $id . "</h2>";
   }

$result = mysql_query("SELECT `cf_id` FROM `TB_data_family` WHERE `family`='" . $form->data['family'] . "'");  
while($row = mysql_fetch_array($result))
   {
$family_id = $row['cf_id'];
echo "<input type='hidden' name='family_id' id='family_id' value='" . $family_id ."'> ";
echo "<h2>Family ID test:  " . $family_id . "</h2>";
   }

?>


After this code, i've add another DB save to the table TB_data_familymember.
It enters a record, but won't enter the above ID's. 😶
brononius 14 Feb, 2014
Hey,

Any idea what I should do so that the new record in the DB use the correct values?
Should I put the returned ID's in a kind of datavalue/array/... ?
brononius 18 Feb, 2014
I've added following custom code between my 2 DB saves, and it works... :p

<?php
$form->data['family_id'] = $form->data['chronoform_data']['cf_id'];
$result = mysql_query("SELECT `id` FROM `TB_users` WHERE `username`='" . $form->data['username'] . "'");  
while($row = mysql_fetch_array($result))
   {
      $familymember_id = $row['id'];
   }
$form->data['familymember_id'] = "$familymember_id";
?>
This topic is locked and no more replies can be posted.