function main_controller() { if ($_GET['action'] == 'search') { $data = getProductsSearch(); view_products($data); } if (empty($_COOKIE['log']) && empty($_COOKIE['pa'])) { echo "<ul><a href=\"http://localhost/companies/index.php?page=reg\" >Зарегистрируйтесь</a>"; echo "<li>или</li>"; echo "<a href=\"http://localhost/companies/index.php?page=login\">Войдите</a>"; } else { $nameUser = $_COOKIE['log']; echo "<form action=logout.php method=post> Привет, {$nameUser}!<input type=submit value=Выход /></form>"; checkUser(); } }
<?php session_start(); function view_products() { $con = mysqli_connect("localhost", "root", "root", "eshop"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con, "SELECT * FROM Product"); $products = array(); while ($row = mysqli_fetch_array($result)) { $rowarray = array("ID" => $row['ID'], "name" => $row['name'], "description" => $row['description'], "stock" => $row['stock'], "price" => $row['price'], "img" => $row['picture']); array_push($products, $rowarray); } echo json_encode($products); mysqli_close($con); // to view all products!!!! // foreach($products as $count => $row) { // foreach($row as $key => $value) { // echo $key.' = '.$value."<br />"; // } // echo "<br>"; // } } view_products();