Advertisement
DarkNetSumrak

Untitled

Feb 2nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2. function db_connect()
  3. {
  4. $server = 'localhost';
  5. $user = 'root';
  6. $password = '';
  7. $dblink = mysqli_connect($server, $user, $password);
  8. $database = 'shop';
  9. $selected = mysqli_select_db($dblink, $database);
  10. }
  11.  
  12. function db_result_to_array($result)
  13. {
  14. $res_array = array();
  15. $count = 0;
  16. while($row = mysqli_fetch_array($result))
  17. {
  18. $res_array[$count] = $row;
  19. $count++;
  20. }
  21. return $res_array;
  22. }
  23.  
  24.  
  25.  
  26.  
  27. function get_products()
  28. {
  29. db_connect();
  30. $query = "SELECT * FROM products ORDER BY id DESC";
  31. $result = mysqli_query($query);
  32. $result = db_result_to_array($result);
  33.  
  34. return $result;
  35. }
  36. ?>
  37. <?
  38. $products = get_products();
  39. foreach ($products as $item):?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement