I have some information in a database in MySql
. I want to show this information on a HTML
page supporting me with PHP
.
When I show the information of only one table there is no problem. The problem comes when I want to show another table on the same page. The code is as follows:
functions.php
<?php
require "config.php"; /*Archivo de conexión a BD*/
class eventosEscolares{
function __construct($db){
$this->db= $db;
}
public function informacionA(){
$query = $this->db->prepare("SELECT * FROM info_a");
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
public function informacionB(){
$query = $this->db->prepare("SELECT * FROM info_b");
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
}
?>
desplegar.php
<?php
require_once "functions.php";
$db = new DatabaseConnection();
$evento = new eventosEscolares($db->pdo);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
<nav class="main-nav">
<div class="container">
<a href="index.html">Inicio</a>
<a href="nosotros.html">Nosotros</a>
<a href="contacto.html">Contacto</a>
<a href="#">Anuncios</a>
</div>
</nav>
<div id="p_div">
<table>
<tr>
<td>Día</td><td>Descripción</td>
</tr>
<?php
$i=0;
$inf=$evento->informacionA();
foreach($inf as $evento){
$i++
?>
<tr><td><?php echo "$evento[dia]" ?></td><td><?php echo "$evento[descripcion]" ?></td></tr>
<?php } ?>
</table>
<table>
<tr>
<td>Día</td><td>Descripción</td>
</tr>
<?php
$i=0;
$infb=$evento->informacionB();
foreach($infb as $evento){
$i++ ?>
<tr><td><?php echo "$evento[dia]" ?></td><td><?php echo "$evento[descripcion]" ?></td></tr>
<?php } ?>
</table>
</div>
</body>
</html>
Doing it this way I get the error:
Fatal error: Call to a member function information () on array in desplegar.php on line 59
How can I correct it so that it shows me both tables correctly?