prevent it from accepting duplicate values with the whole row

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
amyat
Veteran Member
Posts: 45
Joined: 2020-06-24 20:39

prevent it from accepting duplicate values with the whole row

Post by amyat » 2020-06-25 13:36

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: prevent it from accepting duplicate values with the whole row

Post by pbottcher » 2020-06-25 17:54

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.
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.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: prevent it from accepting duplicate values with the whole row

Post by jsetzer » 2020-06-25 18:50

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
Kind regards,
<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 readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1165
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: prevent it from accepting duplicate values with the whole row

Post by onoehring » 2020-06-26 12:30

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)

Code: Select all

$count = sqlValue ("SELECT COUNT(*) FROM yourTable WHERE field1 = `field1RecordValue` AND field2 = `field2RecordValue` ... );
if ($count > 0){
  return FALSE;
} else {
  return TRUE;
}
You will need to investigate in some SQL and PHP knowledge, but you should be able to handle your initial request.

Olaf

amyat
Veteran Member
Posts: 45
Joined: 2020-06-24 20:39

Re: prevent it from accepting duplicate values with the whole row

Post by amyat » 2020-06-27 17:10

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?

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;
	    }
	}
everybody can help me
i trying to understand
sry

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: prevent it from accepting duplicate values with the whole row

Post by pbottcher » 2020-06-27 19:20

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
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.

Post Reply