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