public static function getProductsList()
{
$db = Db::getConnection();
$result = $db->query('SELECT "p.id", "p.name", "c.name", "p.price", "p.code" FROM product as p, category as c WHERE "c.id" = "p.category_id"');
$productsList = array();
$i = 0;
while ($row = $result->fetch()) {
$productsList[$i]['p.id'] = $row['p.id'];
$productsList[$i]['p.name'] = $row['p.name'];
$productsList[$i]['c.name'] = $row['c.name'];
$productsList[$i]['p.code'] = $row['c.code'];
$productsList[$i]['p.category_id'] = $row['c.category_id'];
$productsList[$i]['p.price'] = $row['c.price'];
$i++;
}
return $productsList;
}
<?php foreach ($productsList as $product): ?>
<tr>
<td><?php echo $product['p.id']; ?></td>
<td><?php echo $product['p.code']; ?></td>
<td><?php echo $product['p.name']; ?></td>
<td><?php echo $product['c.name']; ?></td>
<td><?php echo $product['p.category_id']; ?></td>
<td><?php echo $product['p.price']; ?></td>
</tr>
<?php endforeach; ?>
public static function getProductsList()
{
$query = "select p.id, ...";
return Db::getConnection()->query($query);
}
<?php foreach ($productsList as $product): ?>
<tr>
<td><?=$product['id']; ?></td>
</tr>
<?php endforeach; ?>
$result = $db->query('SELECT p.id, p.name, c.name, p.price, p.code FROM product as p, category_id as c WHERE c.id = p.category_id');
...
$result = $db->query('SELECT p.id, p.name, c.name, p.price, p.code FROM product as p LEFT JOIN category as c ON p.category_id = c.id');
...
c.category_id
:$productsList[$i]['p.category_id'] = $row['c.category_id'];