hi everybody...
i'm beginner of appgini user
i have one question about prevent it from accepting duplicate values with the whole row.
'unique' can prevent it but he prevent all data from column
my table have
column data will the same
but need prevent from the same the whole row data
not for 1 column
please help me
thank you
prevent it from accepting duplicate values with the whole row
Re: prevent it from accepting duplicate values with the whole row
Hi,
you cannot do that without coding.
You can use Javascript to check it in the front-end and/or use the hooks file (before_insert / before_update) to check it on the backend side.
you cannot do that without coding.
You can use Javascript to check it in the front-end and/or use the hooks file (before_insert / before_update) to check it on the backend side.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: prevent it from accepting duplicate values with the whole row
I agree with @pböttcher that you need additional programming in case you want some validation and user interface feedback before saving the record.
If you only need to ensure data integrity and don't care too much about UI, you can create a unique constraint on multiple columns on the database table directly.
I think this tutorial should help:
https://www.mysqltutorial.org/mysql-unique/
There is another thread here:
viewtopic.php?t=2759
Regards,
Jan
If you only need to ensure data integrity and don't care too much about UI, you can create a unique constraint on multiple columns on the database table directly.
I think this tutorial should help:
https://www.mysqltutorial.org/mysql-unique/
There is another thread here:
viewtopic.php?t=2759
Regards,
Jan
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: prevent it from accepting duplicate values with the whole row
Hi amyat,
I also totally agree with pbötcher and Jan.
To do what you want, you will need to run some SQL in the /hooks/tablename.php -> before_update and before_insert functions. This SQL could count all rows that have the same value as the "new" (or update) record.
Something like (not tested)
You will need to investigate in some SQL and PHP knowledge, but you should be able to handle your initial request.
Olaf
I also totally agree with pbötcher and Jan.
To do what you want, you will need to run some SQL in the /hooks/tablename.php -> before_update and before_insert functions. This SQL could count all rows that have the same value as the "new" (or update) record.
Something like (not tested)
Code: Select all
$count = sqlValue ("SELECT COUNT(*) FROM yourTable WHERE field1 = `field1RecordValue` AND field2 = `field2RecordValue` ... );
if ($count > 0){
return FALSE;
} else {
return TRUE;
}
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: prevent it from accepting duplicate values with the whole row
thanks to all for helping me...
hi amyat,
i used ur code in my before_insert function.
but i don't get any effect why i dont know.
field1='field1RecordValue'
so i wrote with my column name 'year=yearRecordValue'
is wrong?
everybody can help me
i trying to understand
sry
hi amyat,
i used ur code in my before_insert function.
but i don't get any effect why i dont know.
field1='field1RecordValue'
so i wrote with my column name 'year=yearRecordValue'
is wrong?
Code: Select all
function years_before_insert(&$data, $memberInfo, &$args) {
$count=sqlValue ("SELECT COUNT(*) FROM years WHERE year = `yearRecordValue` AND academic_year = `academic_yearRecordValue` ");
if($count>0){
return FALSE;
}
else
{
return TRUE;
}
}
i trying to understand
sry
Re: prevent it from accepting duplicate values with the whole row
Hi,
you comparison is not getting to where you want it
year = `yearRecordValue`
should look something like
year = {$data['FIELDNAMEOFTHEYEARVALUE']}
But without knowing the datatype or what names you use it is difficult to help further
you comparison is not getting to where you want it
year = `yearRecordValue`
should look something like
year = {$data['FIELDNAMEOFTHEYEARVALUE']}
But without knowing the datatype or what names you use it is difficult to help further
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.