1 (edited by n3Twork 2005-10-01 09:49)

Topic: Add attribute to users profile "sex"

H3LLo

I Want Add a Attribute "sex"  to user info.

in profile user, the user had choice between male or femele.

Can you explain me for do it ?

and i want this modification is showing il user pôst

exemple :

    Registered: 2005-02-19
    Posts: 45
    Sex : Male

Re: Add attribute to users profile "sex"

That's actually very simple, you would need to add a new field to your database, for example, "sex".
You would then need a Drop down menu in the "Personal" page of the profile.
Then in viewtopic.php you would need to add "Sex: " with a simple database query that gathers sex information and displays it under "Posts : ".

3

Re: Add attribute to users profile "sex"

Open profile.php
Find code like this:

                case 'personal':
                {
                        $form = extract_elements(array('realname', 'url', 'location'));

In the end of string put 'sex', now you have smth like this:

                case 'personal':
                {
                        $form = extract_elements(array('realname', 'url', 'location', 'sex'));

Ok..  now let's make form..
Find

<label><?php echo $lang_profile['Realname'] ?><br /><input type="text" name="form[realname]" value="<?php echo pun_htmlspecialchars($user['realname']) ?>" size="40" maxlength="40" /><br /></label>

Under this, add

                            <label><?php echo $lang_profile['Sex'] ?></label>
                            <select name="form[sex]">
                                <option value="male" <?php if ($user['sex'] == 'male') echo ' selected="selected"' ?>><?php echo $lang_profile['Male'] ?></option>
                                <option value="female"<?php if ($user['sex'] == 'female') echo ' selected="selected"' ?>><?php echo $lang_profile['Female'] ?></option>
                            </select>

Now find

<dt><?php echo $lang_profile['Realname'] ?>: </dt>
<dd><?php echo pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['realname']) : $user['realname']) ?></dd>

Ann enter after it

<dt><?php echo $lang_profile['Sex'] ?>: </dt>
<dd><?php echo $user['sex'] ?></dd>

Now let's edit lang/%yourlang%/profile.php
Add there this

'Sex'       =>    'blablabla',
'Male'      =>    'blbqtqtqt',
'Female'  => ' btqqutu',

and don't forget create new field in you database
gl

Hm... every pixel has it's own destiny

Re: Add attribute to users profile "sex"

seva:
nice share.

-Steve

5

Re: Add attribute to users profile "sex"

hm... by the way, we can use users sex in quote messages.. it sounds starnge, but in some languages there are diff. word for english 'wrote', dependent on man sex

Hm... every pixel has it's own destiny

6 (edited by starshiner 2005-10-17 12:54)

Re: Add attribute to users profile "sex"

Seva, spasibo bolshoi for posting this!

I know just enough about php to be dangerous.  Posting this just for clarity's sake, as I figure there must be hacks like me who follow seva's excellent instructions and don't know why the sex doesn't show up in the profile.  And because I'm awfully proud that I figured it out on my own, that you must also add your new database field name to your SQL query:

$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.sex, u.location, u.use_avatar, u.signature, u.disp_topics, u.disp_posts, ....

ss

7

Re: Add attribute to users profile "sex"

of course:)

Hm... every pixel has it's own destiny

Re: Add attribute to users profile "sex"

good job Seva =]

Re: Add attribute to users profile "sex"

This is a very good add-on. I would like to add this to my forum. Since I do not know much about coding, could someone share their advice on how to add the new sex field & what to add into the sql database file??

Anyone's help to this would be most appreciated!

Thanks...

10

Re: Add attribute to users profile "sex"

I've made all the changes seva said, added what starshiner said. Now all I need to do is create the database field right? How do I do that?

11

Re: Add attribute to users profile "sex"

lee wrote:

I've made all the changes seva said, added what starshiner said. Now all I need to do is create the database field right? How do I do that?

YES, how do you create the database fields?

12

Re: Add attribute to users profile "sex"

As starshiner posted...  you need to add u.sex to the code like this

$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.sex, u.location, u.use_avatar, u.signature, u.disp_topics, u.disp_posts, ....

To add it to your database. Go into mysql and run

alter table users add sex varchar(10);

13

Re: Add attribute to users profile "sex"

Odis wrote:

As starshiner posted...  you need to add u.sex to the code like this

$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.sex, u.location, u.use_avatar, u.signature, u.disp_topics, u.disp_posts, ....

To add it to your database. Go into mysql and run

alter table users add sex varchar(10);

Thanks & appreciate!!! ....I'll give it a try!!

Cheers

smile

14

Re: Add attribute to users profile "sex"

thanks for the instructions
how can i make that this information is displayed for example under the avatar?

15 (edited by seva 2006-01-28 15:16)

Re: Add attribute to users profile "sex"

it's easy smile

in viewtopic.php we filled such variables as $user_avatar and two arrays $user_info and $user_contacts.. if u wanna display user sex under the avatar u need put information in the beginning of $user_info. let's do it.

find this (abt lines 209-219)

        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' alt="" />';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' alt="" />';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' alt="" />';
        }
        else
            $user_avatar = '';

and after add such code:

$user_info[] = '<dd>'.$cur_post['sex'];

then find

$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

and  replace it with

$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, u.sex, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

...or just add 'u.sex' somewhere in query

well.. done...

Hm... every pixel has it's own destiny

16

Re: Add attribute to users profile "sex"

thanks a lot seva
very nice!

17 (edited by Endre 2006-03-30 13:54)

Re: Add attribute to users profile "sex"

This worked fine, except for one problem.
When a user hasn't chosen an option, the profile-page displays the Sex and Location on the same line.
View example: http://www.adolfsen.no/parsing.jpg

Any idea how this can be fixed, I'm guessing it's really simple!

Re: Add attribute to users profile "sex"

I've got a variation on the add attribute question:

I've added the attribute, no problem; it even pulls data from the DB, no problem

My issue is that some of the fields are, by necessity, in another table from users.  this is causing an error when changes are made and the user tries to submit (I presume that the UPDATE statement is looking for these fields in users)... but I can't seem to find this particular code in profile.php.

Any help?  let's call this second table "p"

- manzell b

19

Re: Add attribute to users profile "sex"

Odis wrote:

As starshiner posted...  you need to add u.sex to the code like this

$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.sex, u.location, u.use_avatar, u.signature, u.disp_topics, u.disp_posts, ....

To add it to your database. Go into mysql and run

alter table users add sex varchar(10);

does it matter where you have it in query? so if I have it in another section, could I still have u.sex in that spot?

Re: Add attribute to users profile "sex"

If I want change the Male or female with icon how to this?? anyone to help me? wink