Jump to content

Admin access MySQL query


klepec

Recommended Posts

I have a search form. $req is a keyword or an ID number input by user.

As you can see, query checks only for rows where userID matches the current login userID.

 

My question is, how to transform (not independent query for admins) the query to search all rows if user $access is admin (no matter the administrator's own userID).

 

<?php

$userID="something"; (from session)
$access="something" (from session / user or admin)

$query="SELECT esName, esID, esAddress FROM estates WHERE
    (esName LIKE '$req' OR esID LIKE '$req')
    AND userID='$userID'";

mysql_query($query);

?>

 

Thanks in advance :)

Link to comment
Share on other sites

I think you will have to explain this a bit more in detail? The solution I see to your question is far too obvious for it to be the solution...

 

if($access=='admin'){

}

o.O

 

Hey,

Like i said i would like that condition inside mysql query, not writing another query for admins using php if statement.

The problem here is that i have like 10 different queries for 10 different databases and writing another admin query for each one would be a big mess.

Link to comment
Share on other sites

<?php

$access = 'admin';

$admin = $access == 'admin' ? ' OR 1' : '';

$query="SELECT esName, esID, esAddress FROM estates WHERE
    (esName LIKE '$req' OR esID LIKE '$req')
    AND userID='$userID'$admin";

echo $query;

 

This looks good :) Can i ask what "OR 1" does?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.