1
barryc
Making a field unique
  • 2007/12/18 23:35

  • barryc

  • Just can't stay away

  • Posts: 480

  • Since: 2004/3/20


My XOOPS installation is 2.2.4. I chose to use that release because I wanted to be able to create some special fields in the user database. One of those is a member number. I would like to make that field unique, such that duplicate numbers would not be accepted and would return an error message. This would be similar to the email address field, which won't allow entry of a duplicate value. In the Fields admin pages one can make a particular field required, but not unique. Can anyone suggest a way I can hack this?

Barry
Barry Cooper
Sweet Home, Oregon

2
Will_H
Re: Making a field unique
  • 2007/12/19 0:46

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


<{$xoops_uid}> not unique enough?

3
barryc
Re: Making a field unique
  • 2007/12/19 1:28

  • barryc

  • Just can't stay away

  • Posts: 480

  • Since: 2004/3/20


No, because we have both members and non-members of our organization who are registered on the site. That means I have to have a separate field for Member Number. Unless I misunderstand you, I could not use <{$xoops_uid}> for both the user's normal ID and for the member number.

Am I correct?

Barry
Barry Cooper
Sweet Home, Oregon

4
Will_H
Re: Making a field unique
  • 2007/12/19 1:52

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


I don't see why not. would require a bit of hacking on your end.

I haven't used 2.2 in some time, but if I recall you can do something like ths this
<{if yourcustomidvariable == true}>
       <{
$xoops_uid}>
<{else}>
<
a href="<{$xoops_url}>/modules/contact">Become a member!</a>
<{/if}>


I am not really 100% on what you are doing, but you could probably also break it down by groups. I would probably just hack the template rather than try and make a field of it.

So if you open the user profile template you could create a similar statement and print their userid if they are a member of a certain group...

<{php}>
global 
$xoopsuser;
if (
in_array("1",($xoopsUser)?$xoopsUser->getGroups():array(XOOPS_GROUP_PREMIUM))) {
<{/
php]>

Welcome <{$xoops_uname}>, Your Member ID# is <{$xoops_uid}>.

<{php}> } else { <{/php}>
Want to become a premium memberClick Here....

<{
php}> } <{/php}>

5
script_fu
Re: Making a field unique

Its sounds like barry is trying to track different levels of users with another software outside of xoops. It really is hard to come up with the right way to do it with out all the facts...

6
Will_H
Re: Making a field unique
  • 2007/12/19 9:36

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


yeah no der, but that doesn't mean that an "oh well" is in order.....

7
Catzwolf
Re: Making a field unique
  • 2007/12/19 9:38

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


The only way I can think of making a field unique is by making it unique via the database.

8
barryc
Re: Making a field unique
  • 2007/12/19 15:19

  • barryc

  • Just can't stay away

  • Posts: 480

  • Since: 2004/3/20


Apparently I had not made it clear originally. The member number field in my 2.2.4 installation has already been created. Each time somebody joins the organization we register them on out site. The XOOPS database serves as our membership database. If a new member has already registered on the site we edit their record to include such things as their member number, join date, expiration date, etc. A couple of different people are involved in administering this aspect.

At present the database field for member number does not have to be unique so that it is possible to enter duplicate numbers for two different people. To avoid that we have to keep track of the numbers or look up what the last number used was. It would be nice if XOOPS would not allow the people doing this work to accidentally enter a duplicate.

I thought of make the field unique directly in the database and tried it, via phpmyAdmin, but it did not work for some reason. I'll have to try it again. Any advice on how to do that?

I also don't know what the behavior will be if I do succeed in doing that. Will I get a standard XOOPS message if a duplicate is entered?

Barry
Barry Cooper
Sweet Home, Oregon

9
wizanda
Re: Making a field unique
  • 2007/12/19 16:53

  • wizanda

  • Home away from home

  • Posts: 1585

  • Since: 2004/3/21


You could make the field (in PHP admin) for the user number auto_increment, so it adds a new number for each….
Then make a unique index of that field, will stop it making duplicates…

10
Catzwolf
Re: Making a field unique
  • 2007/12/19 16:53

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


You beat me to it :-p

Login

Who's Online

253 user(s) are online (159 user(s) are browsing Support Forums)


Members: 0


Guests: 253


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits