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
https://forums.phpfreaks.com/topic/260980-admin-access-mysql-query/
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.

<?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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.