I can figure out how to loop through a table from the database now that I converted to class it.
Old code
<?php
$sql = "WHERE * FROM Somewere";
$result = $pdo->query($sql);
$products = $result->fetchAll(PDO::FETCH_ASSOC);
?>
<?php foreach ($products as $product) ?>
New code
<?php
class Posts extends Database
{
public function postsToPost()
{
$stmt = $this->connect()->prepare("WHERE * FROM Somewere");
$stmt->execute();
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
?>
<?php foreach ($products as $product) ?>
Do I need now loop inside the class and then output in my page? I'm confused. Thanks