PDA

View Full Version : Custom profile field and username on its own page.


Starscream
10-04-2004, 02:14 AM
I've asked at vb.org, but have not received a response. So, I thought I'd try here.

I want to have a page on my forum that displays only usernames and a ceratin custom profile field. I only want to display the user and profile field if that user has entered something into the field.

I know that I would have to do something with this:

<if condition="$post[field5]">$post[field5]</if>

For example: IF profile field 5 is RPG Name, I want the users to be able to navigate to a page that shows other user's rpg names (and only their Username and RPG name. I don't want all the extra stuff that the memberlist has). I still want the memberlist to show and I have a couple of custom fields I would like to do this with.

I just don't know how to get this on it's own page. Not sure if this is a template-only hack, but thought I'd try to find out. Sorry if it shouldn't be posted here.

Thanks,

Rick

Jolten
10-04-2004, 07:08 AM
You'd have to write a custom query for the database to pull all usernames and the fields and display them on the page. It's definitely NOT a template only hack. It wouldn't be that difficult to do.

You'd need a php page with the query, something like:


$RPG = $DB_site->query("SELECT username, fieldX FROM users, usertextfield ORDER BY username DESC");


Then loop it


while($row=mysql_fetch_object($RPG))
{

$who = $row->username;
$rpgname = $row->fieldX;

eval('$rpgbit .= "' . fetch_template('RPG_listbit') . '";');

}

eval('print_output("' . fetch_template('RPGLIST') . '");');



Then create two templates, RPGLIST for the main page (header and footer in it) using $rpgbit where you wanted the list of usernames, and RPG_listbit to display the names using $who and $rpgname where you what the names. Since there's a loop you really only need to format one row of html using $who and $rpgname for the RPG_listbit, it will repeat as long as there is data to display displaying the next user in the database.

I don't use table prefixes so the query above doesn't show that, if you have a large number of users you may also need a pagination code in there in order to not display all users on a single page. This is all off the top of my head, untested and without any warranty. This is only to give you an idea of what would be involved.

Starscream
10-05-2004, 07:59 PM
Thanks Scott. That helps a lot actually. I haven't tested it yet, but it definately points me in the right direction of where I need to go with it. If you can think of anything else, please let me know.

Thanks,

Rick

Jolten
10-05-2004, 08:15 PM
Glad I could help Rick. The only additional thing I can think of is to match the username with the text field in your query. I left that out before.

More like this:

$RPG = $DB_site->query("SELECT user.userid, user.username, usertextfield.userid, usertextfield.fieldX FROM users, usertextfield WHERE user.userid == usertextfield.userid ORDER BY user.username DESC");