I have a function
that aims to show all the results of an SQL query to the database and need to mount a view with the data of that query.
The function
is as follows:
function buscar_banner(){
global $pdo;
$sql = "SELECT * FROM tb_banners WHERE status = '1'";
$exc = $pdo->query($sql);
$cnt = $exc->rowCount();
return $exc->fetch(); <--- Não sei se uso este
return $exc->fetchAll(); <--- ou este ...
}
$dados = buscar_banner();
TABLE
- ID
- title
- sentence1
- phrase2
- image
- datacad
Since I have this data, I do not know how to return and what structure to use. If you use foreach
or while
. What I want to return is:
<p>Nome banner 1</p>
<p>Nome banner 2</p>
<p>Nome banner 3</p>
...
I have been able to do the process since you have only one result, but I could not do it from the moment I have to return a loop
with the results found.