Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2. include 'inc/header.php';
  3. $cars = $db->prepare("SELECT name, price FROM cars");
  4. $cars->execute();
  5. $cars = $cars->fetchAll(PDO::FETCH_ASSOC);
  6. ?>
  7.  
  8. <table>
  9. <thead>
  10. <tr>
  11. <th>Name</th>
  12. <th>
  13. <a href="?orderBy=price">Price</a>
  14. </th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <?php foreach($cars as $car): ?>
  19. <tr>
  20. <td>
  21. <?php echo $car['name'];?>
  22. </td>
  23. <td>
  24. <?php echo $car['price'];?>€
  25. </td>
  26. </tr>
  27. <?php endforeach;?>
  28. </tbody>
  29. </table>
  30.  
  31. <?php
  32. $orderBy = array('price');
  33.  
  34. $order = 'type';
  35. if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
  36. $order = $_GET['orderBy'];
  37. }
  38.  
  39. $query = 'SELECT * FROM cars ORDER BY '.$order;
  40. )
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement