Page 1 of 2

Username Vs User ID on memberlist_view/profile

Posted: Fri Dec 05, 2014 5:51 pm
by cedricthecat
Hi folks

We've got a modified version of the user profile form, from which we've got a button to link to an extra profile page, which itself holds a number of Custom Profile fields

The button link is done via

Code: Select all

href="memberlist.php?mode=testprofile&un={USERNAME}"
This works a treat, except when there's a user with a name such as "Tom & Jerry", as the ampersand messes up the URL.

I've tried swapping &un={USERNAME} with &u={USER} but this just takes the user to their own custom profile page! I assume that there must be a way to find the user ID of the member whose page you are viewing?

I've been searching around the forum here for the last couple of hours and can't find a solution, so if any kind soul could offer some advice, I'd be very grateful! :mrgreen:

Re: Username Vs User ID on memberlist_view/profile

Posted: Fri Dec 05, 2014 7:00 pm
by Bruce Banner
There's just been a reply to this, but I can't see it.

Re: Username Vs User ID on memberlist_view/profile

Posted: Fri Dec 05, 2014 7:02 pm
by Bruce Banner
Bruce Banner wrote:There's just been a reply to this, but I can't see it.
EDIT: Sorry, ignore me, I'm asleep. I thought I'd started this thread and Cedric had replied to it. Sorry.

Re: Username Vs User ID on memberlist_view/profile

Posted: Fri Dec 05, 2014 11:06 pm
by cedricthecat
:) If you have a similar issue and an answer, I'd be interested to know how it worked out!

Re: Username Vs User ID on memberlist_view/profile

Posted: Sat Dec 06, 2014 12:32 am
by Bruce Banner
cedricthecat wrote::) If you have a similar issue and an answer, I'd be interested to know how it worked out!
Nah. Sorry. I'd just woken from a nap on the couch and my mind was all fuzzy. Wasn't even looking at what the thread was about; just wasn't thinking clearly.

Re: Username Vs User ID on memberlist_view/profile

Posted: Sat Dec 06, 2014 9:51 am
by cedricthecat
Darn, I was getting all excited!

Anyone?!

Re: Username Vs User ID on memberlist_view/profile

Posted: Sat Dec 06, 2014 1:05 pm
by cedricthecat
In the hope that some might be reading this and may have some sage advice, would it be possible to use something along the lines of

Code: Select all

<!-- IF ($user->data['user_id'] == 921) -->
<dd><a href="memberlist.php?mode=testprofile&un=Tom %26 Jerry" class = "button1" " title="Click here to see the extra profile for {USERNAME}">Go to Extra Profile</a>
<!-- ELSE -->
where 921 is the user ID for the ampersandy user name?

The above works when the user is accessing the page themselves, but not sure how to reference the ID for when other users are viewing Tom & Jerry's page......

Re: Username Vs User ID on memberlist_view/profile

Posted: Sat Dec 06, 2014 2:33 pm
by RMcGirr83
You should be using username_clean from the database instead of username

Re: Username Vs User ID on memberlist_view/profile

Posted: Sat Dec 06, 2014 3:28 pm
by cedricthecat
RMcGirr83 wrote:You should be using username_clean from the database instead of username
I'm sure I should, but unfortunately it doesn't work at all with username_clean! :(

Re: Username Vs User ID on memberlist_view/profile

Posted: Sat Dec 06, 2014 7:19 pm
by RMcGirr83
How is this {USERNAME} being populated? Why aren't you using the user id instead?

Re: Username Vs User ID on memberlist_view/profile

Posted: Sun Dec 07, 2014 6:45 pm
by cedricthecat
Hi Rich

In memberlist_view, we're using

Code: Select all

<a href="memberlist.php?mode=testprofile&un={USERNAME}" class = "button1" onmouseover="mOver3(this)" onmouseout="mOut3(this)" title="Click here to see the car profile for {USERNAME}">Go to Car Profile</a>
to get to the extra profile page

Apologies as to the fact that I can't remember exactly why I set it up like this, as this is something I started a year ago and have recently returned to! :oops:

I seem to recall that using the equivalent of testprofile&u={USER} would not work. Certainly, if I try changing to this it just reports "user not found", as when hovered over it doesn't append an ID number after the u=

We've also got a link under the avatar in viewtopic_body to go directly to the extra profile page, and this does work

Code: Select all

<a href="memberlist.php?mode=testprofile&{postrow.U_POST_AUTHOR}" <span style="color: #800000;" title="Click here to see car details for {postrow.POST_AUTHOR}">{postrow.POST_AUTHOR}'s car details</a>
not sure entirely why though!

Interestingly, when hovered over this link displays

/memberlist.php?mode=testprofile&./memberlist.php?mode=viewprofile&u=387

(with 387 being the user_id of the member being tested)

TBH, this is starting to drive me a bit nuts, and I'm having trouble even trying to explain it all, so apologies for this too!

If I try

Re: Username Vs User ID on memberlist_view/profile

Posted: Sun Dec 07, 2014 7:06 pm
by RMcGirr83
The question was how are you setting this {USERNAME} as that isn't set within memberlist.php file in the template variables. You should also be using append_sid for your link.

Re: Username Vs User ID on memberlist_view/profile

Posted: Sun Dec 07, 2014 7:21 pm
by cedricthecat
I've got it in my memberlist.php

Code: Select all

// Grab data
$username	= request_var('un', '', true);
with a fair number of other occurrences of $username, enough in fact to make me think that surely I can't have added them all, although I do admit the memberlist.php has quite a lot of alterations!

TBH, although I do relish a challenge and would like to get to the root of how to solve this puzzle, it's taking too much of my brain up at the moment, and it's not fair to expect help when I can't supply concise answers.

I've checked and we actually only have one member with a name with an ampersand within it. Interestingly, if it's got the ampersand and no spaces, it works fine (so as an example Tom&Jerry as opposed to Tom & Jerry) so I think I'll either just ignore it, or maybe ask that user if they are OK losing the spaces!

Re: Username Vs User ID on memberlist_view/profile

Posted: Mon Dec 08, 2014 12:03 pm
by RMcGirr83

Code: Select all

$username   = request_var('un', '', true);
is a PHP variable you are calling a template variable so how is the template variable being set?

Re: Username Vs User ID on memberlist_view/profile

Posted: Mon Dec 08, 2014 3:46 pm
by cedricthecat
Hi RIch,

Thanks for getting back on this
RMcGirr83 wrote:

Code: Select all

$username   = request_var('un', '', true);
is a PHP variable you are calling a template variable so how is the template variable being set?
In all honesty, I can't remember! :oops:

I've come up with a workaround now though, as it turns out that only one of our three users with an ampersand in their name is affected (I know I really should try to get to the bottom of it.....)

What I've done is popped this into memberlist.php

Code: Select all

$template->assign_var('AND_NAME, "Tom & Jerry");
and this into the viewprofile page, linking to the custom page

Code: Select all

<!-- IF USERNAME == AND_NAME -->
<a href="memberlist.php?mode=testprofile&un=Tom %26 Jerry" class = "button1"  title="Click here to see the extra profile for {USERNAME}">Go to Extra Profile</a>
<!-- ELSE -->
<dd><a href="memberlist.php?mode=testprofile&un={USERNAME}" class = "button1"  title="Click here to see the extra profile for {USERNAME}">Go to Extra Profile</a>
<!-- ENDIF -->
Undoubtedly messy but it works - just need to make sure I don't let any more "&" names through! (oh and also I need to go back and address the append_sid issues!)