Could someone help me and tell me why he sends me that message?
Attached the code:
<?php
try{
$conexion = new PDO('mysql:host=localhost;dbname=organizer', 'root', ''); } catch(PDOexception $e){
echo 'Error ' . $e->getMessage(); }
?>
<!DOCTYPE html> <html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/estilos-inicio.css">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>TASKS | Reportes no tan importantes</title>
</head>
<body>
<?php require('views/header.php'); ?>
<div class="contenedor">
<div class="post">
<p class="titulo">REPORTES NO TAN IMPORTANTES</p>
<br>
<hr>
<article>
<?php
foreach($reportes = $conexion->query('SELECT descripcion FROM tareas WHERE categoria = "No tan importante"') as $reporte){ // ESTA LINEA ES LA DEL ERROR!!!!!
echo '<li>' . $reporte . '</li>';
}
?>
</article>
</div>
</div>
<?php require('views/footer.php'); ?>
</body>
</html>
The error is quite simple, when using $pdo->query() directly, you will get the data with the fetch_style
PDO::FETCH_BOTH
style, that is, it is possible to access it by numerical index and index of the column name in theselect
. Therefore your variable $report is of typearray
and it is not possible to concatenate it directly.The solution can be the previous one or specify the style of obtaining the data, for your case with
FETCH_COLUMN
would be enough, that isBut the code looks very confusing and unreadable as it is, you should get the data before entering the
foreach
, (example)You should probably call the array element by its respective index in the foreach: