How do I get the username of the logged-in user? I am working on a site where on a page I am querying some data related to my project.

Here I have many clients and I have given all of them access to project search page. On search page I run a query according to the fields selected by the user and display the result as a table on the page itself. But my query is as such that it is not user dependent.

I just want to ensure that each user has a specific set of output for itself (i.e not all the table would be displayed to all users).

How do I get the username or user ID of the logged-in user?
You can use the global $user object:

An object representing the user currently visiting the site.
Contains preferences and other account information for logged-in users. When a user is not logged-in, the $user-&gt;uid property is set to 0.

e.g.
global $user;
$name = $user-&gt;name;
$id = $user-&gt;uid;

// or
$name = $GLOBALS['user']-&gt;name;
$id = $GLOBALS['user']-&gt;uid;