Hi,
I want to prevent a value from being stored twice in the database table.
I have created a switch:
name: check_species_duplicate
data provider: {var / empty: save_beob_new.row.Fund.species}
values: true: {error: type already exists} {redirect: index}
My save data function (name: save_beob_new) is in the event: save_new_beob
{fn: check_species_duplicate}
{fn: save_beob_new}
{Redirect: index}
The problem is that now I always get the error message and no new record is saved.
The new record comes from a form
name: beob_new_form
data provider: {var: read_beobs}
There is also a drop-down box in the form, which gives the value necessary for the duplicate check:
name: species
Name: Fund [species]
Option:
= Select type
{var: read_specieslist}
Unfortunately, I could not solve the problem.
Maybe it's easier in the event: save_new_beob using a PHP or Javascript for the check.
Or you have to set a click event for the duplicate check in the form: species submit button?
Thanx
F.
I want to prevent a value from being stored twice in the database table.
I have created a switch:
name: check_species_duplicate
data provider: {var / empty: save_beob_new.row.Fund.species}
values: true: {error: type already exists} {redirect: index}
My save data function (name: save_beob_new) is in the event: save_new_beob
{fn: check_species_duplicate}
{fn: save_beob_new}
{Redirect: index}
The problem is that now I always get the error message and no new record is saved.
The new record comes from a form
name: beob_new_form
data provider: {var: read_beobs}
There is also a drop-down box in the form, which gives the value necessary for the duplicate check:
name: species
Name: Fund [species]
Option:
= Select type
{var: read_specieslist}
Unfortunately, I could not solve the problem.
Maybe it's easier in the event: save_new_beob using a PHP or Javascript for the check.
Or you have to set a click event for the duplicate check in the form: species submit button?
Thanx
F.
READ data first to check for the value.
ok,
What do I have to change now, so that the duplicate entry in the table does not come?
"[species] => machaon, Papilio, (Linnaeus, 1758)" Is a duplicate entry.
"Data saved successfully" is wrong. The entry may not come.
What do I have to change now, so that the duplicate entry in the table does not come?
"[species] => machaon, Papilio, (Linnaeus, 1758)" Is a duplicate entry.
"Data saved successfully" is wrong. The entry may not come.
Array ( [conn] => beobachtungsliste [article_id] => 642 [event] => save_new_beob [Fund] => Array ( [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Licht [bestimmung] => Augenschein [bemerkung] => ) [button33] => [99b2d8d194748b816f5a52b3f980c167] => b4ce5ced2dcfe13c2fd5cd076217278c [84a67b6ec4a2db8ac9e867546b14d6f3] => e3fd1c323f9bbf9c545ea617cbe69597 [joomla_user_state] => logged_in [Itemid] => 112 [option] => com_content [view] => article [id] => 36 [beobachtungsliste] => )Array ( [read_beob] => Array ( [log] => Array ( [0] => SELECT `Fund`.`beof_id` AS `Fund.beof_id`, `Fund`.`user_id` AS `Fund.user_id`, `Fund`.`beo_id` AS `Fund.beo_id`, `Fund`.`mapid_v` AS `Fund.mapid_v`, `Fund`.`datum` AS `Fund.datum`, `Fund`.`species` AS `Fund.species`, `Fund`.`anzahl` AS `Fund.anzahl`, `Fund`.`stadium` AS `Fund.stadium`, `Fund`.`geschlecht` AS `Fund.geschlecht`, `Fund`.`beobachtung` AS `Fund.beobachtung`, `Fund`.`bestimmung` AS `Fund.bestimmung`, `Fund`.`bemerkung` AS `Fund.bemerkung`, `Fund`.`photo` AS `Fund.photo`, `Fund`.`created` AS `Fund.created`, `Fund`.`modified` AS `Fund.modified` FROM `mtb_beobachtung` AS `Fund` WHERE `Fund`.`beo_id` = '642' AND `Fund`.`species` LIKE '%%' GROUP BY `Fund.beof_id`; ) [var] => Array ( [0] => Array ( [Fund] => Array ( [beof_id] => 903 [user_id] => 909 [beo_id] => 642 [mapid_v] => 3 [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => 1 [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Tag [bestimmung] => Augenschein [bemerkung] => [photo] => [created] => 2019-07-02 17:10:13 [modified] => 2019-07-27 18:57:27 ) ) [1] => Array ( [Fund] => Array ( [beof_id] => 1072 [user_id] => 909 [beo_id] => 642 [mapid_v] => 0 [datum] => 2019-07-11 [species] => crataegi, Aporia, (Linnaeus, 1758) [anzahl] => 5 [stadium] => Imago [geschlecht] => Ohne [beobachtung] => Am Tag [bestimmung] => GU [bemerkung] => [photo] => [created] => 2019-07-23 16:17:06 [modified] => 2019-07-25 18:05:02 ) ) ) ) [check_species_duplicate] => Array ( [finished] => 1 [var] => ) [save_beob_new] => Array ( [data] => Array ( [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Licht [bestimmung] => Augenschein [bemerkung] => [created] => 2019-07-31 00:05:46 [user_id] => 909 [beo_id] => 642 [beof_id] => ) [_success] => Data saved successfully [log] => Array ( [0] => INSERT INTO `mtb_beobachtung` (`datum`, `species`, `anzahl`, `stadium`, `geschlecht`, `beobachtung`, `bestimmung`, `bemerkung`, `created`, `user_id`, `beo_id`, `beof_id`) values ('2019-07-11', 'machaon, Papilio, (Linnaeus, 1758)', '', 'Imago', 'o. A.', 'Am Licht', 'Augenschein', '', '2019-07-31 00:05:46', '909', '642', '') ON DUPLICATE KEY UPDATE `datum` = '2019-07-11',`species` = 'machaon, Papilio, (Linnaeus, 1758)',`anzahl` = '',`stadium` = 'Imago',`geschlecht` = 'o. A.',`beobachtung` = 'Am Licht',`bestimmung` = 'Augenschein',`bemerkung` = '',`created` = '2019-07-31 00:05:46',`user_id` = '909',`beo_id` = '642',`beof_id` = ''; ) [var] => Array ( [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Licht [bestimmung] => Augenschein [bemerkung] => [created] => 2019-07-31 00:05:46 [user_id] => 909 [beo_id] => 642 [beof_id] => 1298 ) ) )
If you find an entry, don't save. If you don't find an entry, save. And your read_data checking for the existing entry should just return first matching, not all of them.
I do not get the right save when matching the data.
read_beobs_for_duplicate
Where condition:
species = {data: species} Continue
Group: Fund.species
check_species_duplicate:
{Var / empty: read_beobs_for_duplicate}
value: true: {error: double} {redirect: index}
read_beobs_for_duplicate
Where condition:
species = {data: species} Continue
Group: Fund.species
check_species_duplicate:
{Var / empty: read_beobs_for_duplicate}
value: true: {error: double} {redirect: index}
Array ( [cont] => manager [conn] => beobachtungsliste [event] => save_new_beob [article_id] => 642 [Fund] => Array ( [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Licht [bestimmung] => Augenschein [bemerkung] => ) [button33] => [99b2d8d194748b816f5a52b3f980c167] => 2f231acfe5ff5004c96e00420b926a01 [84a67b6ec4a2db8ac9e867546b14d6f3] => 5da48029476714c1a03464b15647a72f [joomla_user_state] => logged_in [option] => com_chronoconnectivity6 [Itemid] => )Array ( [read_beobs_for_duplicate] => Array ( [log] => Array ( [0] => SELECT `Fund`.`beof_id` AS `Fund.beof_id`, `Fund`.`user_id` AS `Fund.user_id`, `Fund`.`beo_id` AS `Fund.beo_id`, `Fund`.`mapid_v` AS `Fund.mapid_v`, `Fund`.`datum` AS `Fund.datum`, `Fund`.`species` AS `Fund.species`, `Fund`.`anzahl` AS `Fund.anzahl`, `Fund`.`stadium` AS `Fund.stadium`, `Fund`.`geschlecht` AS `Fund.geschlecht`, `Fund`.`beobachtung` AS `Fund.beobachtung`, `Fund`.`bestimmung` AS `Fund.bestimmung`, `Fund`.`bemerkung` AS `Fund.bemerkung`, `Fund`.`photo` AS `Fund.photo`, `Fund`.`created` AS `Fund.created`, `Fund`.`modified` AS `Fund.modified` FROM `mtb_beobachtung` AS `Fund` WHERE `Fund`.`user_id` = '909' AND `Fund`.`beo_id` = '642' GROUP BY `Fund.species`; ) [var] => Array ( [Fund] => Array ( [beof_id] => 1072 [user_id] => 909 [beo_id] => 642 [mapid_v] => 0 [datum] => 2019-07-11 [species] => crataegi, Aporia, (Linnaeus, 1758) [anzahl] => 5 [stadium] => Imago [geschlecht] => Ohne [beobachtung] => Am Tag [bestimmung] => GU [bemerkung] => [photo] => [created] => 2019-07-23 16:17:06 [modified] => 2019-07-25 18:05:02 ) ) ) [check_species_duplicate] => Array ( [finished] => 1 [var] => ) [save_beob_new] => Array ( [data] => Array ( [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Licht [bestimmung] => Augenschein [bemerkung] => [created] => 2019-07-31 12:04:35 [user_id] => 909 [beo_id] => 642 [beof_id] => ) [_success] => Data saved successfully [log] => Array ( [0] => INSERT INTO `mtb_beobachtung` (`datum`, `species`, `anzahl`, `stadium`, `geschlecht`, `beobachtung`, `bestimmung`, `bemerkung`, `created`, `user_id`, `beo_id`, `beof_id`) values ('2019-07-11', 'machaon, Papilio, (Linnaeus, 1758)', '', 'Imago', 'o. A.', 'Am Licht', 'Augenschein', '', '2019-07-31 12:04:35', '909', '642', '') ON DUPLICATE KEY UPDATE `datum` = '2019-07-11',`species` = 'machaon, Papilio, (Linnaeus, 1758)',`anzahl` = '',`stadium` = 'Imago',`geschlecht` = 'o. A.',`beobachtung` = 'Am Licht',`bestimmung` = 'Augenschein',`bemerkung` = '',`created` = '2019-07-31 12:04:35',`user_id` = '909',`beo_id` = '642',`beof_id` = ''; ) [var] => Array ( [datum] => 2019-07-11 [species] => machaon, Papilio, (Linnaeus, 1758) [anzahl] => [stadium] => Imago [geschlecht] => o. A. [beobachtung] => Am Licht [bestimmung] => Augenschein [bemerkung] => [created] => 2019-07-31 12:04:35 [user_id] => 909 [beo_id] => 642 [beof_id] => 1320 ) ) )
What do you mean you don't get the right save?
In the case above
"species machaon" is saved. But the species is already included in the table.
The "species crataegi" is displayed to me under "read_beobs_for_duplicate" in the debugger. But it is not double.
The problem is: Duplicate entries should be avoided before saving.
In the case above it is like this:
In the table are the species
machaon
crataegi
Now I want to save a new species. For testing, I enter a species (machaon), which would be twice in the table after saving.
But that is not desired.
"species machaon" is saved. But the species is already included in the table.
The "species crataegi" is displayed to me under "read_beobs_for_duplicate" in the debugger. But it is not double.
The problem is: Duplicate entries should be avoided before saving.
In the case above it is like this:
In the table are the species
machaon
crataegi
Now I want to save a new species. For testing, I enter a species (machaon), which would be twice in the table after saving.
But that is not desired.
Looks like your read data action is looking for entries where the article ID AND the user ID match. Is that right?
That's how it works now. It looks like. :-)
save_beob_new
Update condition:
Fund.species = {data:Fund.species} Stop
read_beobs_for_duplicate
type: first matching record
Where conditions
Fund.species LIKE {data:Fund.species} Stop
Fields to retrieve: Fund.species
check_species_duplicate
provider: {var/empty:read_beobs_for_duplicate}
values setup: false:{error:doppelt}{redirect:index}
under Event save_new_beob:
{fn:read_beobs_for_duplicate}
{fn:check_species_duplicate}
{fn:save_beob_new}
{redirect:index}
save_beob_new
Update condition:
Fund.species = {data:Fund.species} Stop
read_beobs_for_duplicate
type: first matching record
Where conditions
Fund.species LIKE {data:Fund.species} Stop
Fields to retrieve: Fund.species
check_species_duplicate
provider: {var/empty:read_beobs_for_duplicate}
values setup: false:{error:doppelt}{redirect:index}
under Event save_new_beob:
{fn:read_beobs_for_duplicate}
{fn:check_species_duplicate}
{fn:save_beob_new}
{redirect:index}
[read_beobs_for_duplicate] => Array ( [log] => Array ( [0] => SELECT (a bunch of fields) WHERE `Fund`.`user_id` = '909' AND `Fund`.`beo_id` = '642' GROUP BY `Fund.species`;
So you're sure that's right?
Yes, every registered user can only see and manage their data. And every species may occur only once in the watchlist for each individual observation.
Example:
User 909
- beo_id: 642 (Location_1)
- - on the day: 11.7.2019
- - species (1003, machaon)
- - species (1004, brassicae)
User 909
- beo_id: 642 (Location_1)
- - on the day: 12.7.2019
- - species (1003, machaon)
- - species (1004, brassicae)
User 909
- beo_id: 642 (Location_1)
- - at the light: 12.7.2019
- - species (1024, micro1)
- - species (1025, micro2)
User 909
- beo_id: 642 (Location_1)
- - on bait: 12.7.2019
- - species (1024, micro1)
- - species (1028, micro5)
User 909
- beo_id: 643 (Location_2)
- - on the bait: 13.7.2019
- - species (1024, micro1)
- - species (1028, micro5)
--------------------
User 910
- beo_id: 642 (Location_1)
- - on the day: 13.7.2019
- - species (1003, machaon)
- - species (1005, podalirius)
User 910
- beo_id: 644 (Location_3)
- - on the day: 14.7.2019
- - species (1003, machaon)
- - species (1004, brassicae)
User 910
- beo_id: 642 (Location_1)
- - at the light: 12.7.2019
- - species (1024, micro1)
- - species (1025, micro2)
User 910
- beo_id: 642 (Location_1)
- - on the bait: 12.7.2019)
- - species (1024, micro1)
- - species (1028, micro5)
------------------------
I think for the administration of the data, it is important in the case that the ID of the place (beo_id) of the system may be assigned only 1x. Whether user 909 or 910 creates the "beo_id".
I remember that after reading your question ...
Example:
User 909
- beo_id: 642 (Location_1)
- - on the day: 11.7.2019
- - species (1003, machaon)
- - species (1004, brassicae)
User 909
- beo_id: 642 (Location_1)
- - on the day: 12.7.2019
- - species (1003, machaon)
- - species (1004, brassicae)
User 909
- beo_id: 642 (Location_1)
- - at the light: 12.7.2019
- - species (1024, micro1)
- - species (1025, micro2)
User 909
- beo_id: 642 (Location_1)
- - on bait: 12.7.2019
- - species (1024, micro1)
- - species (1028, micro5)
User 909
- beo_id: 643 (Location_2)
- - on the bait: 13.7.2019
- - species (1024, micro1)
- - species (1028, micro5)
--------------------
User 910
- beo_id: 642 (Location_1)
- - on the day: 13.7.2019
- - species (1003, machaon)
- - species (1005, podalirius)
User 910
- beo_id: 644 (Location_3)
- - on the day: 14.7.2019
- - species (1003, machaon)
- - species (1004, brassicae)
User 910
- beo_id: 642 (Location_1)
- - at the light: 12.7.2019
- - species (1024, micro1)
- - species (1025, micro2)
User 910
- beo_id: 642 (Location_1)
- - on the bait: 12.7.2019)
- - species (1024, micro1)
- - species (1028, micro5)
------------------------
I think for the administration of the data, it is important in the case that the ID of the place (beo_id) of the system may be assigned only 1x. Whether user 909 or 910 creates the "beo_id".
I remember that after reading your question ...
This topic is locked and no more replies can be posted.