Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Transaction Patterns » PopUp - Link1 table
PopUp - Link1 table [message #5558] Mon, 23 May 2016 04:44 Go to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Hi Tony,

I have two tables (training_exercises, key exercise_id, rdcaccount_id and training_categories, key category_id, rdcaccount_id) which I linked (table training_category_exercises, key cat_training_category_id, cat_rdcaccount_id, ex_training_exercise_id, ex_rdcaccount_id) with a link1 pattern to define which exercise is related to which category because an exercise can be related to more than one category.

Now I want to choose an exercise which is possible with a popup1 pattern for table training_exercises. But I want to choose the category first, see the linked exercises and choose one of these linked exercises.

Is this possible and if yes, how and which pattern should I use?
Re: PopUp - Link1 table [message #5559 is a reply to message #5558] Mon, 23 May 2016 05:59 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
There are several ways in which this can be done.

1) If you go to the Data Dictionary and look at either "Add Child Relationship" or "Add Parent Relationship" you will see that on the left is a dropdown list which enables you to select the database, and on the right is a popup button which will show you the tables which exist within that database.

2) You could use a POPUP2 pattern with category as the outer/top entity and exercise as the inner/bottom entity. If you are unable to pass the identity of the category to this popup then take a look at option #2 in FAQ7 which will show you how you can call a POPUP1 pattern to select the outer entity before the POPUP2 screen is displayed.

3) There is always AJAX, but I do not provide any facilities for this in RADICORE.


Re: PopUp - Link1 table [message #5561 is a reply to message #5559] Tue, 24 May 2016 10:37 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
I think the only way to realize this is the second way you proposed. I think I understand the way to do this, too. I read the option #2 in FAQ79. But I have problems to find the right way.

I created a PopUp1 for table category. I created a PopUp2 for the (link) table. I inserted the following code (as shown in #2 of FAQ79) in the class of the PopUp2 (link) table.

If I call the PopUp2 function I get a white screen telling me that the website can never finish the query.

Where is my fault?


function _cm_initialise ($where)
// perform any initialisation for the current task.
{
if (empty($where)) {
if (isset($GLOBALS['return_from'])) {
if ($GLOBALS['return_from'] == 'htm_training_plan_uebungskategorie(popup1)') {
// nothing selected from popup screen
$this->scriptPrevious($GLOBALS['errors']);
} // if
} // if

$pattern_id = getPatternId();
if (strtolower($pattern_id) == 'popup2') {
// request_id has not been supplied yet, so get it now via a popup
$this->scriptNext('htm_training_plan_uebungen_kategorie(popup2)');
} // if
} // if
return $where;

} // _cm_initialise
Re: PopUp - Link1 table [message #5563 is a reply to message #5561] Wed, 25 May 2016 04:39 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Your code mentions two different popup forms - htm_training_plan_uebungskategorie(popup1) and htm_training_plan_uebungen_kategorie(popup2). If you look at FAQ79 you will see that the same popup form is mentioned twice. Your mistake is that it is calling one popup form, then checking that it has returned from another, which causes a loop.

The logic behind that code is as follows:
1) If, at the start of the POPUP2 form, there is no value for the primary key of the outer entity then it calls a popup to obtain it.
2) If, upon returning from that popup, no value has been chosen then it will return to the previous form with an error message.
3) If a value from the popup has been selected the current POPUP2 form will use it to read the outer entity so it can then retrieve related entries from the inner entity.


Re: PopUp - Link1 table [message #5564 is a reply to message #5563] Wed, 25 May 2016 06:21 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Thank you for your explanation. I got it right now and (at the moment) it works.

I will now try to expand the information in the PopUp2 screen with elements coming from the training_exercise table. Because at the moment I only see the key fields.

Is it possible to open an instance for this table and filling in the data in the fieldarray? And if yes, where do I have to do this best?
Re: PopUp - Link1 table [message #5565 is a reply to message #5564] Wed, 25 May 2016 07:28 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Each table class will, by default, only be able to retrieve data from its own table. If your inner class is for a link table that only contains foreign keys to two other tables then you will not be able to show any additional data from those foreign tables until you generate a query which contains a JOIN to one of those foreign tables.

Re: PopUp - Link1 table [message #5566 is a reply to message #5565] Wed, 25 May 2016 09:57 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
This means that I have to change the $this->sql_select and $this->sq_from .... statements probably similiar to those like in the x_tree_node sample, isn't it?

And where do I place this code best? In the _cm_PopUpReturn after retreiving the keys of PopUp1? Or somewhere else?
Re: PopUp - Link1 table [message #5567 is a reply to message #5566] Wed, 25 May 2016 10:12 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Take a look at FAQ08 and FAQ84

Re: PopUp - Link1 table [message #5572 is a reply to message #5567] Thu, 26 May 2016 12:58 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
I read FAQ08 and FAQ84 but I struggle all day long with the SQL syntax and I don't know what I am doing wrong. I try to improve my SQL skills (as you suggested) but this is at the moment obiously too much for me.

This component script of the popup2 will show no entries.

$outer_table = 'training_plan_uebungskategorie'; // name of outer (parent) table
$inner_table = 'training_plan_uebungen_kategorie'; // name of inner (child) table
$screen = 'training_plan_uebungen_kategorie.popup2.screen.inc'; // file identifying screen structure

// customise the SQL SELECT statement
$outer_sql_select = null;

$inner_sql_select = null;
$inner_sql_from = 'training_plan_uebungen_kategorie '
. 'LEFT JOIN training_plan_uebungen ON ('
. 'training_plan_uebungen.training_plan_uebung_no = training_plan_uebungen_kategorie.u_training_plan_uebung_no AND '
. 'training_plan_uebungen.rdcaccount_id = training_plan_uebungen_kategorie.u_rdcaccount_id) ';
$inner_sql_where = null;

require 'std.list2.popup.inc'; // activate page controller

The following error message and the SQL statement will be shown if the default sort order of the link table is a field value of one of the parent tables (linked with a relationship).

Fatal Error: MySQL: Unknown column 'training_plan_kategorie_desc' in 'order clause' (# 1054)

SQL query: SELECT SQL_CALC_FOUND_ROWS * FROM training_plan_uebungen_kategorie LEFT JOIN training_plan_uebungen ON (training_plan_uebungen.training_plan_uebung_no = training_plan_uebungen_kategorie.u_training_plan_uebung_no AND training_plan_uebungen.rdcaccount_id = training_plan_uebungen_kategorie.u_rdcaccount_id) WHERE

training_plan_uebungen.rdcaccount_id='1'

AND training_plan_uebungen_kategorie.k_training_plan_kategorie_i d='ABW-GRDU' AND training_plan_uebungen_kategorie.k_rdcaccount_id='1' ORDER BY training_plan_kategorie_desc asc LIMIT 10 OFFSET 0

The expression "training_plan_uebungen.rdcaccount_id='1'" is obviously inserted by the framework. If I change the values of rdcaccount_id to 1, the records will not be shown.
Do I have to change the where clause, too?
Re: PopUp - Link1 table [message #5574 is a reply to message #5572] Thu, 26 May 2016 14:48 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
You have not identified where the ORDER BY training_plan_kategorie_desc is coming from. It must be defined by you somewhere as the framework would not insert it.

If a table contains the field 'rdcaccount_id' then you must supply a value. One should normally be associated with your menu user_id. You will then only be able to see those entries on the table which have the same value for 'rdcaccount_id' as defined for your user_id, or the value 'rdcaccount_id=1'. If no records are shown then there are none that qualify.


Re: PopUp - Link1 table [message #5575 is a reply to message #5574] Fri, 27 May 2016 03:09 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
1. Yes I have defined it in the table properties. If I remove the default order seq in the table properties, the changed code will not be executed. Only the framework code is executed.

2. I am logged in with rdcaccount_id No 4. The 'normal' PopUp2 form shows all entries coming from the choosen category. It shows entries from rdcaccount No 4 and 2, although I have created two relationships for the two rdc_account_id fields in the primary key of the link table (key: cat_id, cat_rdcaccount_id, exercise_id, ex_rdcaccount_id).
Re: PopUp - Link1 table [message #5577 is a reply to message #5575] Fri, 27 May 2016 05:41 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
If you are logged in with rdcaccount_id=4 then you should only see records for rdcaccount_id = 1 or 4. You should NOT see any records for rdcaccount_id=2.

Re: PopUp - Link1 table [message #5578 is a reply to message #5577] Fri, 27 May 2016 10:00 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Yes, I know. With PopUp1 for exercises everything works fine. But with the construction PopUp2/PopUp1 and with the link table not. Do I have to mention something special with the link table, because the key consists of the key of the two combined tables?
Re: PopUp - Link1 table [message #5582 is a reply to message #5578] Sat, 28 May 2016 05:09 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
I notice that your link table contains two rdcaccount_id columns, one for each of the parent tables. Unless the rdcaccount_id column is part of the primary key in those parent tables it is not necessary to define them as foreign keys in the link table. The way that a POPUP2 works is that you first identify a single row on the parent/outer table, then use the primary key as the WHERE clause when reading from the child/inner table. If you are reading entries from the child table which do not belong to the parent then there is something wrong.

Re: PopUp - Link1 table [message #5585 is a reply to message #5582] Tue, 31 May 2016 05:00 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
I changed the primary keys of the two parent tables. I removed the rdcaccount_id field because I don't really need it in the primary key. Now everything works fine, just as you explained. I get the data of the parent table in PopUp2, too. Exactly the way I want.
But there is one question left. One of the fields that I get from the parent table for popUp2 has subtype 'image'. In the PopUp2 screen I only see the image file path. Where can I change the field specs for that field to show me the image?
Re: PopUp - Link1 table [message #5586 is a reply to message #5585] Wed, 01 June 2016 05:18 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Take a look at FAQ133

Re: PopUp - Link1 table [message #7413 is a reply to message #5586] Sun, 15 March 2020 05:59 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Hi Tony,
I have a new problem concerning this topic. I have two tables. One which stores all the teams for each season and one that stores the team members of these teams. Now I want to insert team members for a new season with this construction.
In the _cm_initialise() method of the team member table class I have the first problem, because I have to change $where to '' to get all possible teams from the popup1 form of the team table. I think that this is the reason why I have additional problems and why the code which you provided in FAQ79 doesn't work in this case.
When selecting one or more teams, I get the team members for this team shown in the popup2 form. (I cannot change the $settings['select_one'] = TRUE for the (popup1) team table. Even if I try this in the _cm_popupCall() method.)
I thought that I could see the selected team members in the _cm_popupReturn() method and I thought that I could insert them via an add4 pattern? I hope this will work. I am not at this point so I haven't tried it yet.
In the popup2 form I have this time only the choose button. The choose null button isn't displayed.
I attachded my code of the _cm_initialise() method. Can you tell me what is wrong with it?


function _cm_initialise ($where, &$selection, $search)
// perform any initialisation for the current task.
{
// wenn htm_orga_mannschaften_kontakte(popup2) aufgerufen wird, werden alle verfügbaren Mannschaften angezeigt
switch ($GLOBALS['task_id']) {
case 'htm_orga_mannschaften_kontakte(popup2)':
if ($GLOBALS['return_from'] == '') {
$where = '';
$pattern_id = getPatternId();
if (strtolower($pattern_id) == 'popup2') {
// request_id has not been supplied yet, so get it now via a popup
$this->scriptNext('htm_orga_mannschaften(popup1)');
} // if
}
else {
if (empty($selection)) {
if (isset($GLOBALS['return_from'])) {
if ($GLOBALS['return_from'] == 'htm_orga_mannschaften(popup1)') {
// nothing selected from popup screen
$this->scriptPrevious($GLOBALS['errors']);
} // if
} // if
} // if
} // else
}; // switch ($GLOBALS['task_id'])

return $where;

} // _cm_initialise
Re: PopUp - Link1 table [message #7414 is a reply to message #7413] Sun, 15 March 2020 12:51 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
It looks like you have two tables called TEAM and TEAM_MEMBER which are in a one-to-many relationship with TEAM as the 'one' and TEAM_MEMBER as the 'many'. Your POPUP1 screen should therefore refer to TEAM on its own while the POPUP2 should refer to TEAM as the 'outer' entity and TEAM_MEMBER as the 'inner'.

You do not say which pattern you are using to call the POPUP2 screen. It cannot be an ADD4 as it does not have a visible screen.

FAQ79 states that you would normally call a POPUP2 screen by passing in $where the identity of a single row in the 'outer' entity, in which case it will display that selected row in the outer zone and populate the inner zone will all associated rows from the inner entity. However, if the $where string is empty you will need code in the _cm_initialise() of the inner entity to pause the execution of the POPUP2 screen and call a POPUP1 screen in order to prove a non-empty value for the $where string.

You say that your first problem is that in the _cm_initialise() method of the TEAM table you have to clear the contents of the $where string so that it will retrieve all possible entries. The value which appears in the $where string for a popup form is set in the _cm_popupCall() method which calls that popup, so if you want an empty $where string then you must set $where to NULL (or an empty string) in that _cm_popupCall() method. It is only when you call a POPUP2 screen that the $where string may point to a row on the 'outer' entity. If a non-blank value is supplied the POPUP2 form will perform a lookup on the 'outer' entity using this value then populate the 'inner' with rows which belong to that 'outer' row. If the $where string you pass to a POPUP2 form is empty then it will fail unless you follow FAQ79.

You say that you cannot change $settings['select_one'] = true for the POPUP1 form when activated from the _cm_initialise() method in the TEAM_MEMBER table, but this is not correct. If you look at the arguments for the scriptNext() function (see https://www.tonymarston.net/php-mysql/functions-and-variable s.html#func.scriptnext) you will see that the 4th argument is an array of task details. You can provide this argument with a value such as $array['settings'] = 'select_one=TRUE' in order to provide the desired effect. If you want multiple settings you must separate them with an '&' such as as in 'select_one=TRUE&choose_single_row=TRUE'

When you say that the 'Choose Null' button is not displayed in the POPUP2 form this is because $settings['select_one'] has been set to true for that popup.


Re: PopUp - Link1 table [message #7415 is a reply to message #7414] Sun, 15 March 2020 15:16 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
It looks like you have two tables called TEAM and TEAM_MEMBER which are in a one-to-many relationship with TEAM as the 'one' and TEAM_MEMBER as the 'many'. Your POPUP1 screen should therefore refer toTEAM on its own while the POPUP2 should refer to TEAM as the 'outer' entity and TEAM_MEMBER as the 'inner'. That is right.

You do not say which pattern you are using to call the POPUP2 screen. It cannot be an ADD4 as it does not have a visible screen. The popup2 will be called as described in FAQ79. I thought that it would be possible to insert the selected items with the add4 pattern.

FAQ79 states that you would normally call a POPUP2 screen by passing in $where the identity of a single row in the 'outer' entity, in which case it will display that selected row in the outer zone and populate the inner zone will all associated rows from the inner entity. However, if the $where string is empty you will need code in the _cm_initialise() of the inner entity to pause the execution of the POPUP2 screen and call a POPUP1 screen in order to prove a non-empty value for the $where string. I think that the problem with $where is because I have a navigation button in the list2 pattern of the team_member table. I thought that it would be possible to choose the 'new' team in the team_member table and then add the team members of the last saison team. This is why the §where isn't empty. $where has the key values of the 'new' team member primary key.

You say that your first problem is that in the _cm_initialise() method of the TEAM table you have to clear the contents of the $where string so that it will retrieve all possible entries. The value which appears in the $where string for a popup form is set in the _cm_popupCall() method which calls that popup, so if you want an empty $where string then you must set $where to NULL (or an empty string) in that _cm_popupCall() method. I tried this but maybe I made mistakes and I didn't succeed.

It is only when you call a POPUP2 screen that the $where string may point to a row on the 'outer' entity. If a non-blank value is supplied the POPUP2 form will perform a lookup on the 'outer' entity using this value then populate the 'inner' with rows which belong to that 'outer' row. If the $where string you pass to a POPUP2 form is empty then it will fail unless you follow FAQ79. I get the correct team members shown in the popup2 form of the choosen team. But I don't get them in the _cm_popupReturn() method.

You say that you cannot change $settings['select_one'] = true for the POPUP2 form when activated from the _cm_initialise() method in the TEAM_MEMBER table, but this is not correct. If you look at the arguments for the scriptNext() function (see https://www.tonymarston.net/php-mysql/functions-and-variable s.html#func.scriptnext) you will see that the 4th argument is an array of task details. You can provide this argument with a value such as $array['settings'] = 'select_one=TRUE' in order to provide the desired effect. If you want multiple settings you must separate them with an '&' such as as in 'select_one=TRUE&choose_single_row=TRUE' I can change the settings of the popup2 form. But not of the popup1 form to show the possible teams.

When you say that the 'Choose Null' button is not displayed in the POPUP2 form this is because $settings['select_one'] has been set to true for that popup. That is right. I can see it now if I change the setting from False to true.

I hope that you have more information to understand my problem.

[Updated on: Sun, 15 March 2020 15:22]

Report message to a moderator

Re: PopUp - Link1 table [message #7416 is a reply to message #7415] Mon, 16 March 2020 13:02 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
The popup2 will be called as described in FAQ79. I thought that it would be possible to insert the selected items with the add4 pattern.
You still have not identified from where the POPUP2 will be called. It would appear that a task of pattern X will be calling the popup, and when it returns it will add each selection to the database using an ADD4 task. Is this correct?

This is why the §where isn't empty. $where has the key values of the 'new' team member primary key.
This is not correct. The $where string that you pass to a POPUP2 task is used to select a single row in the 'outer' table so that it can then select associated rows from the 'inner' table. You cannot pass a $where string which identifies a TEAM_MEMBER if the 'outer' table is TEAM.

I get the correct team members shown in the popup2 form of the choosen team. But I don't get them in the _cm_popupReturn() method.
When you return from a POPUP2 screen the value in $selection is an array which contains the primary key of every entry you selected in the 'inner' zone of that popup.

I can change the settings of the popup2 form. But not of the popup1 form to show the possible teams.
In the _cm_initialise() method of the TEAM table you can call the scriptnext() function to activate the POPUP1 task with an optional 4th parameter in the format array('settings' => 'select_one=TRUE')


Re: PopUp - Link1 table [message #7417 is a reply to message #7416] Tue, 17 March 2020 07:45 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
I think that I didn't explain it right so I attached a file with three screen shots and I hope that my explanation is now better.

The first screen shot shows the LIST2 pattern of the new season ('Auflistung Mannschafts-Mitglieder') where I want to add the team members of a former season. For this purpose I have the button 'Neu (Team)' which will show me the available teams of former seasons (screenshot 2 - 'Choose Mannschaften'). I don't know how I can change the array('settings' => 'select_one=TRUE') for this POPUP1 pattern. This selection will be passed to the POPUP2 pattern with all the team members of the choosen team (screenshot 3 - 'Choose Mannschaften Kontakte'). After selecting team members and pressing 'Choose' the initial LIST2 pattern is shown again. In the _cm_popupReturn() method isn't an array with the selected members. This method is not called.

The popup2 will be called as described in FAQ79. I thought that it would be possible to insert the selected items with the add4 pattern.
You still have not identified from where the POPUP2 will be called. It would appear that a task of pattern X will be calling the popup, and when it returns it will add each selection to the database using an ADD4 task. Is this correct?
This is my idea. But I don't know if this works because I have not selected items in my _cm_popupReturn() method.

This is why the §where isn't empty. $where has the key values of the 'new' team member primary key. Yes, that's why I have to change it to '' before calling the popup1 pattern to obtain the available teams.

I get the correct team members shown in the popup2 form of the choosen team. But I don't get them in the _cm_popupReturn() method.
When you return from a POPUP2 screen the value in $selection is an array which contains the primary key of every entry you selected in the 'inner' zone of that popup.
That's what I thought. But in my code seems to be an error because I don't get this array in _cm_popupReturn().

I can change the settings of the popup2 form. But not of the popup1 form to show the possible teams.
In the _cm_initialise() method of the TEAM table you can call the scriptnext() function to activate the POPUP1 task with an optional 4th parameter in the format array('settings' => 'select_one=TRUE')
But the POPUP1 pattern is called in the _cm_initialise() method of the TEAM MEMBER class after suspending the POPUP2 pattern.
  • Attachment: PopUp2-1.jpg
    (Size: 452.85KB, Downloaded 1065 times)
Re: PopUp - Link1 table [message #7418 is a reply to message #7417] Wed, 18 March 2020 06:28 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
If I understand you correctly you have 3 forms as follows:
1) A LIST2 pattern called "Auflistung Mannschafts-Mitglieder" which has TEAM as the outer table and TEAM_MEMBER as the inner.
2) A POPUP1 pattern called "Choose Mannschaften" which has TEAM as the only table
3) A POPUP2 pattern called "Choose Mannschaften Kontakte" which has TEAM as the outer table and TEAM_MEMBER as the inner.

When you call the POPUP1 task from the LIST2 task you can set $setting['select_one'] = TRUE in the _cm_popupCall method of the LIST2 task. When the POPUP1 task terminates it returns to the LIST2 task with the selected rows in the 3rd argument of the _cm_popupReturn() method.

When you call the POPUP2 task from the LIST2 task you are supposed to supply a value for the primary key of the outer table so that it can retrieve that entry and then display associated entries from the inner table. If you do NOT supply a value then you can suspend the processing of that POPUP2 task by calling a POPUP1 task as detailed in FAQ79.

I do not see any popup buttons on the LIST2 screen, so how are they being activated? If you are using navigation buttons then these do not operate in the same way as popup buttons.


Re: PopUp - Link1 table [message #7419 is a reply to message #7418] Wed, 18 March 2020 12:23 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
My fault was that I told you popup button but I have a navigation button. You can see the navigation button on the first screen as 'Neu (Team)'. I thought that the way of operation would be the same.
Where can I see how the way of operation is with navigation buttons?
Re: PopUp - Link1 table [message #7420 is a reply to message #7419] Thu, 19 March 2020 05:23 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Please refer to How do navigation buttons work? and What is a popup?

Re: PopUp - Link1 table [message #7421 is a reply to message #7420] Fri, 20 March 2020 08:31 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
I read the two articles and now I know a little bit more.
When I select the team members which I want to insert in new team and I press the choose button the _cm_popupReturn() method in orga_mannschaften_kontakte.class.inc will not be called.
I stepped with my debugger through the code and can see that in getPatternId() in the include.library.inc the $pattern_id is changed to 'unknown' although the script var is correct (htm_orga_mannschaften_kontakte(popup2).
Can this be the reason why the _cm_popupReturn() isn't called?
Re: PopUp - Link1 table [message #7422 is a reply to message #7421] Sat, 21 March 2020 07:52 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Popup tasks do not work correctly when called from anything other than a popup button. A popup button can only be used within a zone where the database table can be added or updated as these zones will be able to call the popupReturn() method when returning from a popup. A LIST2 screen does not contain any calls to popupReturn() which is why the rows you selected in the popup never appear in the LIST2 task.

I have tried modifying a LIST2 task to include a navigation button for both a POPUP1 and POPUP2 task, and they work as I have described.

I have looked at the call to getPatternId(), and it returns the value found in $_SESSION['pages'][$script_id]['pattern_id'], so if 'unknown' is being returned you can only be using a value for $script_id which does not exist in $_SESSION['pages']. By default this is the current script which ALWAYS has an entry in $_SESSION['pages'], so are you supplying a value for $scrip_id which is no longer active?


Re: PopUp - Link1 table [message #7423 is a reply to message #7422] Sun, 22 March 2020 04:45 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Thank you for providing me a possible solution. But do you have an idea how I could solve my problem in a different, better way? I have very often this situation where I want to insert child records from earlier seasons.
Re: PopUp - Link1 table [message #7424 is a reply to message #7423] Sun, 22 March 2020 05:19 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
You need to start by identifying if you have the right database structure. If you have a collection of teams, and a collection of players, then in order to identify which players can be members of which teams you have a classic many-to-many situation where a team can have many players and a player can belong to many teams. No database can support a many-to-many relationship, so you have to implement a pair of one-to-many relationships with a "link" or "intersection" table in the middle. So you would end up with a structure such as this:

TEAM => MEMBER <= PLAYER

where TEAM => MEMBER is one-to-many and PLAYER => MEMBER is one-to-many.

This then allows you to have such tasks as "Show me all the PLAYERS who are members of TEAM x" and "show me all the TEAMS to which PLAYER x is a member"

This is precisely the situation for which I developed the ADD3 pattern?


Re: PopUp - Link1 table [message #7425 is a reply to message #7424] Sun, 22 March 2020 09:41 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Thank you for your advice. I assume that this is your default solution for this situation?
In this (my) case I haven't thought of it yet. I have used the add3 pattern with a 'link' or 'intersection' table for example for counting the presence of team members or for assigning exercises to different exercise classes. This works fine.
The link table consists of the pkey fields of the two 'One'-tables. Can I add additional fields to the 'link' table? What I need are fields for height, weight etc. for the team members of this team for this year/season. These values will change from year to year.
In the Summary of 'How to handle a Many-to-Many relationship with PHP and MySQL' you wrote, that additional fields would make it much more complicated. Would this work at all? If not, have you a solution for this problem?

[Updated on: Mon, 23 March 2020 02:58]

Report message to a moderator

Re: PopUp - Link1 table [message #7426 is a reply to message #7425] Mon, 23 March 2020 06:47 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Yes, you can add additional fields to the link/intersection table as I have done it myself many times. In fact if you look at the MENU database the MNU_MENU and MNU_NAV_BUTTON tables are examples of this. They both are the "many" in two one-to-many relationships where both of the "one" tables are the same table (MNU_TASK).

Re: PopUp - Link1 table [message #7427 is a reply to message #7426] Mon, 23 March 2020 16:57 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
Okay. Thank you. Then I will restructure my tables in this way.
This would mean that this construction is better/smarter than a hierarchical parent/child structure for such situations as I used to create. It's new for me. I never thought of such a solution.
Re: PopUp - Link1 table [message #7515 is a reply to message #7427] Wed, 12 August 2020 06:54 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 439
Registered: May 2014
Senior Member
I just wanted to tell you that I found a way which fits my needs best. I expanded my parent table structure with the key fields with the prefix lup for lookup. In these fields I store the parent occurence via a popup. In my list2 pattern I can now call an add5 pattern to show all the child occurences from this record.
Normally a team is defined for one saison/period and consists of about 20 persons. And normally the team in the subsequent saison has about 80% of the team members from last year. In this way I can insert all team members and delete the members who have left the team. This is quite comfortable for me.
If I use a link1 pattern I have to scroll through all possible (100 til 200 or even more) team members. This takes too much time for me. This was just to give you a feedback.
Re: PopUp - Link1 table [message #7516 is a reply to message #7515] Sat, 15 August 2020 04:38 Go to previous message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Thanks for that feedback. It's good to know that you have found an acceptable solution. Sometimes you have to approach a problem from several different angles before you see the best solution.

Previous Topic: Filepicker - choose Null button
Next Topic: List view (List3)
Goto Forum:
  


Current Time: Tue Dec 03 13:11:58 EST 2024

Total time taken to generate the page: 0.08391 seconds