Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function db_connect()
- {
- $server = 'localhost';
- $user = 'root';
- $password = '';
- $dblink = mysqli_connect($server, $user, $password);
- $database = 'shop';
- $selected = mysqli_select_db($dblink, $database);
- return $dblink;
- }
- function db_result_to_array($result)
- {
- $res_array = array();
- $count = 0;
- while($row = mysqli_fetch_array($result))
- {
- $res_array[$count] = $row;
- $count++;
- }
- return $res_array;
- }
- function get_products($dblink)
- {
- $query = "SELECT * FROM products ORDER BY id DESC";
- $result = mysqli_query($dblink,$query);
- $result = db_result_to_array($result);
- return $result;
- }
- ?>
- <?
- $products = get_products(db_connect());
- foreach ($products as $item):?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement