SQL Query to return just single value

I have a database setup for authorisation to a website, using PHP i can get the response below

Name / Group1 / Group2 / Group3
Me / Y / N / Y

Query I am using is :-

Select [Group2] from Table where Name = 'Me'

but this is returning

Array
(
    [0] => Array
        (
            [group2] => Y
        )

)

I am looking for it to just return Y
adznonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
hmm, it depends on how you query your database and what framework (methods) you use. Using query/fetch returns a row set, thus the arrays. When you need a scalar you need to return the column:

e.g. something like

$query = $connection->query("Select [Group2] from Table where Name = 'Me'");
$rowset = $query->fetch();
$scalar = $rowset["Group2"];

Open in new window

Pawan KumarDatabase ExpertCommented:
Pls try this...

Array[0][group2]
ste5anSenior DeveloperCommented:
or

$query = $connection->query("Select [Group2] from Table where Name = 'Me'");
$scalar = $query->fetchColumn();

Open in new window

adznonAuthor Commented:
Sorry i a bit at a loss how to add it in. This is the full code that i am using that returns the before mentioned array but needs to bring back just a Y to the String $checkaccess

admin.php - File
$checkaccess = $dh->getUserData('admin');

dbquery.php - File
// #################################################################################
// Database Querys
// #################################################################################
      public function select($query){
                  $stmt = sqlsrv_query($this->conn,$query);
                  $result = array();
                  while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
                        //echo "<pre>";print_r($row);exit;
                        $result[] = $row;
                  }
                  return $result;
      }
      public function query($query){
                  $stmt = sqlsrv_query($this->conn,$query);
                  return $stmt;
      }
// #################################################################################
// Access Check
// #################################################################################
      public function getUserData($type){
            $tpxid = "";
            $tpxid = trim(substr($_SERVER['AUTH_USER'], strrpos($_SERVER['AUTH_USER'], '\\') + 1));
            $query = "  Select [admin] from [Users] where TPXid = '$tpxid'";
            //echo $query;exit;
            $result = $this->select($query);
            echo "<pre>";print_r($result);exit;
            //echo $result;exit;
            if($result == "Y"){
                  //echo $result."<BR>";
                  echo "Result is Yes";exit;
                  return $result;      
            }
            else{
                  //echo "Result is No";Exit;
                  $_SESSION['error_msg'] = "You are not an $type";
                  return;
                  
            }
ste5anSenior DeveloperCommented:
First of all: use the [code][/code] tags (or the CODE button) to emebed code. This increases readbility.

Untested:
dbquery.php - File
 // #################################################################################
 // Database Querys
 // #################################################################################
       public function scalar($query){
                   $stmt = sqlsrv_query($this->conn,$query);
                   $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
                   return sqlsrv_get_field($row, 0);
       }
 // #################################################################################
 // Access Check
 // #################################################################################
       public function getUserData($type){
             $tpxid = "";
             $tpxid = trim(substr($_SERVER['AUTH_USER'], strrpos($_SERVER['AUTH_USER'], '\\') + 1));
             $query = "  Select [admin] from [Users] where TPXid = '$tpxid'";
             $result = $this->scalar($query);
             echo "<pre>";print_r($result);exit;
             if($result == "Y"){
                   echo "Result is Yes";exit;
                   return $result;
             }
             else{
                   $_SESSION['error_msg'] = "You are not an $type";
                   return;
             }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.