PDO Switch Case Does Not Display

0

Changed more within the title yet, the case works but does not display the result.

<?php

$sql = "SELECT tipo FROM publicidade WHERE posicao='Lateral' ORDER BY RAND() LIMIT 1";
$stmt = DB::prepare($sql);
$stmt->execute();
$exibe = $stmt->fetchAll();
foreach ($exibe as $u) {
$tipo = $u->tipo;  // <-- corrigido baseado nos comentarios
switch ($tipo) {
case 'imagem':
echo "<img src='img/publicidade/$u->idpublicidade/$u->imagem' heigth='150' width='100%'>";
break;
case 'flash':
echo "<embed src='img/publicidade/$u->idpublicidade/$u->flash' width='720' height='90'></embed>";
break;
case 'codigo':
echo "$u->codigo";
break;
}}

changed

    
asked by anonymous 10.03.2015 / 18:09

1 answer

2

FetchAll does what it says: it fetches all results for a query. Since search fetches results, you will get an indexed array.

You should change all queries to prepared statements and replace the following:

  • % by% by% by%
  • or $stmt->fetchAll(); by $stmt->fetchAll(PDO::FETCH_ASSOC);
10.03.2015 / 20:13