Solved

How do i exclude the current logged in user from a PHP\MySqlscript

Posted on 2013-01-18
7
434 Views
Last Modified: 2013-02-07
Hi

I have an Andriod application that logs in and querys Mysql PHP script. The script returns a list of books within a date then returns the list into a list view. All this works absolutely fine.
Now i want to bring the same list back but do not include the books for user thats logged in.

At the moment it returns all the books including the user im logging at, could someone suggets away of not to include the current logged in user?

Heres the current PHP script, note i have added the <>1 (this is the userId im logging as) just as a quick work around, abviously this is not a good way though:

$result = mysql_query("SELECT users.uid, users.name, users.book
FROM users
WHERE EXISTS (SELECT 0 FROM available A1, available A2
WHERE A1.uid =1 AND A2.uid = users.uid
AND A1.AvailableDates = A2.AvailableDates
AND users.uid <>1)") or die(mysql_error());


I would imagine i would need to get the current users id and exclude that from the query (somehow)?
0
Comment
Question by:wilko100
7 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 250 total points
ID: 38792992
Probably the user id you're trying to get is in session variable, like
$_SESSION['userid']
You would hav eto know how it's set up during logging in.
Can you post the login script ?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 38793066
All scripts that use PHP client authentication follow the same design pattern.  It is described in this article.  Look for $_SESSION['uid'] to see the sort of thing you would want to exclude from the query results set.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0
 
LVL 9

Expert Comment

by:rinfo
ID: 38796143
Cant say what other thinks, but i personally find this very confusing and unclear.

Now i want to bring the same list back but do not include the books for user thats logged in.

At the moment it returns all the books including the user im logging at, could someone suggets away of not to include the current logged in user?

What exactly does this means.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 11

Expert Comment

by:mcnute
ID: 38796222
Maybe he want to exclude the books which the user submitted?!
0
 
LVL 9

Expert Comment

by:rinfo
ID: 38796301
I think a better option could have been
1. user table userid , username
2.books table userid,bookname
3.available table userid,available date

Now to get all the book name which does not belong to a particular userid
use a query like

Select u.userid,u.username ,b.bookname from user
inner join books b on b.userid = u.userid
where u.userid <> 1

I am not sure what purpose available date is serving on your query.

An alternative could be ( based on your table structure - and my assumptions)
select u.userid,u.username,b.bookname from
user u where u.userid <> 1
0
 

Author Comment

by:wilko100
ID: 38804960
Roads_Roads and Ray_Paseur, that sounds like just the job, one thing left then, my login function and the all books funtion are in 2 seperate files i.e. Login.php and Get_All_Book.php.

So if, in the login.php file i declare the $_SESSION and then pass the user id into the $_SESSION, can i then carry this over to the Get_All_Books.php file as $_SESSION [variable'']?

As an example:

//Login.php file

//Set up the variable in login.php file
$loggedinuser=addslashes($_POST['uid']);

//$loggedinuser will be the person who has logged into the app
$_SESSION['login_user']=$loggedinuser;



//Get_All_Books.php file

//Pull the varibale across from login.php
$user_check=$_SESSION['login_user'];

//Run query and exclude logged in user, query simplified for this example
$result = mysql_query("SELECT users.uid, users.name, users.book
FROM users
WHERE users.uid <>$user_check)") or die(mysql_error());
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38804977
That's the whole point of a Session. Yes you can transfer the variable from your login page to the get all books page.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
uploading image to a profile page 7 33
Trigger usage 2 59
Hacked File Timestamps 4 47
Could you point how to give Bootstrap's open/ close menu effect ? 25 26
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now