forked from jstolpe/blog_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimit.php
48 lines (41 loc) · 1000 Bytes
/
limit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// include global things for use
include 'global_data.php';
$sql = array( // array keyed by the various sql statments we can run
'LIMIT' => '
SELECT
*
FROM
drinks
WHERE
size = :size
ORDER BY
expiration_date ASC
LIMIT 1
',
'LIMITOFFSET' => '
SELECT
*
FROM
drinks
WHERE
size = :size
ORDER BY
expiration_date ASC
LIMIT 3, 3
'
);
// check url for sql statement to run
$sql = isset( $_GET['filter'] ) && isset( $sql[$_GET['filter']] ) ? $sql[$_GET['filter']] : $sql['LIMIT'];
$params = array( // keys must match the variables in the sql so they can get replaced with the value
':size' => '12oz'
);
// prepare the sql
$statement = $database->prepare( $sql );
// execute the sql
$statement->execute( $params );
// get the query data
$queryDrinks = $statement->fetchAll();
// display the html
displayViewHtml( $sql, $allDrinks, $queryDrinks, $statement );
?>