Need help: IF / ELSE Statement to limit query results?

I want the code to first check if the logged in user is an admin. If they are an admin, I want it to run the first query (where it shows all records). If they are not an admin, I want it to run the second query which adds a where clause (so it only shows the records of the logged in users username). In my database, admins have a 1 in the admin column, while users have a 0. This is the code i have so far:

[php]if ($admin_session == “1”) {
$query = “SELECT * FROM timesheet JOIN employee ON timesheet.emp_id = employee.emp_id ORDER BY employee.emp_id”
} else {
$query = “SELECT * FROM timesheet JOIN employee ON timesheet.emp_id = employee.emp_id WHERE employee.username LIKE ‘$login_session’ ORDER BY employee.emp_id”
}[/php]

Anyone know what I’m doing wrong?

hello AVCP333, do following changes 1.) if $admin_session return integer than use if condition as below if ($admin_session == 1) and if it's string than if condition as below (same currently you are using) if ($admin_session == "1")

2.) in your query you are missing semi colon in the end of query because of your getting black page when run this script.
chanege you both query statement as
$query = “SELECT * FROM timesheet JOIN employee ON timesheet.emp_id = employee.emp_id ORDER BY employee.emp_id”;
and
$query = “SELECT * FROM timesheet JOIN employee ON timesheet.emp_id = employee.emp_id WHERE employee.username LIKE ‘$login_session’ ORDER BY employee.emp_id”;

i hope this will helpful for you.

SR

Sponsor our Newsletter | Privacy Policy | Terms of Service