How to get the ending of the url address?

Hello everyone!
I am wondering how I can access the ending of my url address.
For exampel: www.castingvault.eu/willy
And I wand the name "willy" only and then process and use it in my php code.

Usually you write the url like this:
www.castingvault.eu/members.php?mem=willy
and the following is how to access it.

$mem = $_GET['mem'];

Then you access the username: willy.

Can anyone help please
Thank you!

//Willy Lukwago

Filter results in MySQL with PHP

Hello everyone!
I working on a social network alike page whare I want to implement a messaging system.
I can do all that and I have it working.

What I want is, when I get two or more messages from someone. I only want to display the lates message from that member in the message list.
Right now it shows all three in the list like this.

Message from Willy
Message from Willy
Message from Tom
Message from Willy

But I only want to show one for all like this.

Message from Willy
Message from Tom

Even though Willy has sent many message.
Please help!