PHP with PDO returning BLOB records with foreach

2

Good afternoon guys, I'm new here (first question), but Stack has already helped me in many situations.

Here's the problem:

I'm developing an application and on a certain page there is a user profile page. On this page, a div that displays the photos of users who belong to the same industry as the logged in user.

Query:

$query3 = "SELECT USR.EMAIL, USR.IMG_PERFIL, IMG.IMAGEM FROM IN_USUARIOS USR, IN_IMAGENS IMG WHERE USR.IMG_PERFIL = IMG.ID AND USR.SETOR =:setor AND USR.ID !=:id";

Running:

$stmt3 = $conn->prepare($query3);
$stmt3->bindValue(':setor',$result1['SETOR']);
$stmt3->bindValue(':id',$result1['ID']);
$stmt3->execute();
$result3=$stmt3->fetchAll(PDO::FETCH_ASSOC);

* $ result1 = Returns all user data

Listing:

 <ul class="friends">
  <?php
   foreach($result3 as $key => $value ) 
    { 
      echo
        '<li>
          <div class="profile-pic">
            <img width="35" height="35" title="'. $value['EMAIL'] .'" src="data:image/jpeg;base64,'.base64_encode(stream_get_contents($value['IMAGEM'])).'">
          </div>
         </li>';
    }
  ?

The code presents the images, but always the same, in case the image of the last colleague in the data array: (should be the image corresponding to each of the colleagues of the logged in user.

var_dump($result3):

array(4){[0]=>array(3){["EMAIL"]=>
    string(30) "[email protected]"
    ["IMG_PERFIL"]=>
    string(1) "4"
    ["IMAGEM"]=>
    resource(3) of type (stream)
  }
  [1]=>
  array(3) {
    ["EMAIL"]=>
    string(29) "[email protected]"
    ["IMG_PERFIL"]=>
    string(1) "6"
    ["IMAGEM"]=>
    resource(4) of type (stream)
  }
  [2]=>
  array(3) {
    ["EMAIL"]=>
    string(26) "[email protected]"
    ["IMG_PERFIL"]=>
    string(1) "7"
    ["IMAGEM"]=>
    resource(5) of type (stream)
  }
  [3]=>
  array(3) {
    ["EMAIL"]=>
    string(26) "[email protected]"
    ["IMG_PERFIL"]=>
    string(1) "5"
    ["IMAGEM"]=>
    resource(6) of type (stream)
  }

}

  • Viewing page code:

I must be forgetting some detail in my foreach. I count on your help.

Thank you.

    
asked by anonymous 05.01.2017 / 20:39

0 answers