Hi all,

I have a pagination script that works great apart from one last thing I require some pointers on please.

The help i need is with the SELECT query - currently the select query works, but i am bringing back all records, I am trying to bring only certain records.

$query = "SELECT count(to_user) FROM $tbl_name";

what I am trying to do is only bring records back for the user who is logged in.

I am using session data where the users username is stored as "login"

I have tried a few ways to only bring back the logged in users records from the mysql database using the session data.

users session data is as follows:

[]//set session for login
if ($_GET['SESS_LOGIN']) {
     $login = $_GET['SESS_LOGIN'];
} else if (isset($_SESSION['SESS_LOGIN'])) {
     $login = $_SESSION['SESS_LOGIN'];
} else {
    header("location: http://website.com/restricted-area.php");
   exit();
}[]

My question here would be ??

How can i use the above session data and incorporate the users username in the following query -

$query = "SELECT count(to_user) FROM $tbl_name";

the above (to_user) is how data is stored in mysql -

Sorry all, after posting and reading my post I have solved the problem

what I should have been using is the following -

$query = "SELECT count(to_user) FROM $tbl_name WHERE to_user='".$_SESSION['SESS_LOGIN']."'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.