So you want to store a value in the session scope when a user clicks a link. How you solve this should depend on what should happen when the user clicks. Are the clicks causing navigation and a new get request, or is it simply registering the name value in the session?
If the information is only needed on the client, you should consider using sessionStorage.
https://developer.mozilla.org/en/DOM/Storage#sessionStorage
Using jQuery you could set a value to sessionStorage like this:
$('a').click(function(){
sessionStorage.setItem('name', $(this).attr('data-name');
});
...and access it later on:
sessionStorage.getItem('name');
Keep in mind that sessionStorage is not supported by older browsers. If older browsers are important, you could use cookies instead. Cookies are sent to the server with each request, so if you set it with javascript on the click event, the value will be included in the next request, thus you can read it form the $_COOKIE array.
document.cookie = 'name=' + $(this).attr('data-name');
$value = $_COOKIE['name'];
You could fallback for older browsers by using feature detection:
if(sessionStorage){ /* do the session storage part */ }
else{ /* do the cookie part :) */ }
If you need to send the value to the server immediately you should consider using an ajax request, like Prashant Singh mentions in his answer.
My axamples use custom data attributes. I'm not sure about the content of your name values, and it's not clear how your markup looks like. You could use the name attribute if the names from mysql fits the attrbute semantically. Alternatively you could use the rel attribute, if the name describes a relation between the list and the target of the links.
$nameyou want to set. As long as the user has not clicked any link you don't know, so I wonder how you want to solve this. What is the criteria of the click?