php function selectAllItems sql SELECT id title author pubyear price F

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
function selectAllItems(){
$sql = "SELECT id, title, author, pubyear, price FROM catalog";
$link = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
if(!$result = mysqli_query($link, $sql)) return false;
$items = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
return $items;
}
?>
<?php
foreach($goods as $item){
?>
<tr>
<td><?= $item['title']?></td>
<td><?= $item['author']?></td>
<td><?= $item['pubyear']?></td>
<td><?= $item['price']?></td>
<td><a href="add2basket.php?id=<?= $item['id']?>">В корзину</a></td>
</tr>
<?php }?>