954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MYSQL SELECT COUNT query

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.

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

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 -
[code]$query = "SELECT count(to_user) FROM $tbl_name";[code]

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

LloydFarrell
Junior Poster
101 posts since Dec 2009
Reputation Points: 10
Solved Threads: 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']."'";
LloydFarrell
Junior Poster
101 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: