Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'inc/header.php';
- $cars = $db->prepare("SELECT name, price FROM cars");
- $cars->execute();
- $cars = $cars->fetchAll(PDO::FETCH_ASSOC);
- ?>
- <table>
- <thead>
- <tr>
- <th>Name</th>
- <th>
- <a href="?orderBy=price">Price</a>
- </th>
- </tr>
- </thead>
- <tbody>
- <?php foreach($cars as $car): ?>
- <tr>
- <td>
- <?php echo $car['name'];?>
- </td>
- <td>
- <?php echo $car['price'];?>€
- </td>
- </tr>
- <?php endforeach;?>
- </tbody>
- </table>
- <?php
- $orderBy = array('price');
- $order = 'type';
- if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
- $order = $_GET['orderBy'];
- }
- $query = 'SELECT * FROM cars ORDER BY '.$order;
- )
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement