0

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 -

Edited by Reverend Jim: Fixed formatting

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by LloydFarrell
0

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']."'";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.