Jump to content

pdo return array deformed


purencool

Recommended Posts

phpfreaks

 

I am querying a database using pdo but I keep getting an array that returns two results. As you can see from the  array below it returns the id and result and then repeats the result .  I only want the  keys with text to be returned.

 

Any help would be great.

 

( [0] => Array ( [Ticket_ID] => 2 [0] => 2 [Customer_id] => 1 [1] => 1 [business_Name] => [2] =>

 

my database method is

    private function queryFetchAllPDO($query) {

        try {
            $this->dataObj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sth = $this->dataObj->prepare($query);
$sth->execute();
echo"I am here";
$result = $sth->fetchAll();
print_r($result);
   //         $stmt = $this->dataObj->query($query);
//            $stmt->setFetchMode();
//            $result = $stmt->fetchAll();
        } catch (PDOException $e) {

            $e->getMessage();
        }

        return $result;
    }

 

and the query  method is

    private function clieViewHome() {
        //find user id
        $sql = "SELECT Customer_id  FROM customer WHERE Username='" . $this->user . "'";
        $sessAccess = $this->connection->getQueryFetchPDO($sql);
        foreach ($sessAccess as $value) {
            $userID = $value;
        }
        //place into query
        $sql = "SELECT *  FROM tickets WHERE Customer_id ='" . $userID . "'";
        $tableArr = $this->connection->getQueryFetchAllPDO($sql);
         print_r($tableArr);
        foreach ($tableArr as $key => $value) {
            $return .= "<tr>\n";
            foreach ($tableArr[$key] as $value2) {
                $return .="<td>" . $value2 . "</td>\n";
            }
            $return .= "</tr>\n";
        }

        
        return $return;
    }

 

Link to comment
https://forums.phpfreaks.com/topic/227106-pdo-return-array-deformed/
Share on other sites

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.