0
Good afternoon, I have a function with a query to search a list of photos of a certain product in the Product class:
class Produto {
private $mysql;
public function __construct(mysqli $mysql){
$this->mysql = $mysql;
}
public function listaFotosPorId(string $id):array{
$result = $this->mysql->query("SELECT f.*,p.id FROM tbfotosproduto as f join tbprodutos as p on f.id_produto=p.id WHERE id_produto = {$id}");
$fotos = $result->fetch_all(MYSQLI_ASSOC);
return $fotos;
}
}
It relates to another table that contains the main product information. My intention here is to create a list of all product photos of a specific id on a page and display in the list the name, photo and individual id of the photos. But when I make the call, the id that appears in the field is the product id and not the photo id. The call is as follows:
$produto = new Produto($mysql);
$foto = $produto->listaFotosPorId($_GET['id']);
foreach($foto as $fotos):
?>
<tr>
<td>
<?=$fotos['id']?>
</td>
<td>
<?=$fotos['nome']?>
</td>
<td>
<img src="<?=$fotoPath.$fotos['nome']?>" alt="">
</td>
<td>
<a href="admin-excluir-foto.php?id=<?= $fotos['id']?>">Excluir</a>
</td>
</tr>
<?php endforeach?>
When I call the appears the product id and not the photo. Being that I am selecting the photo table...