php prepared statement and conditional

Solutions on MaxInterview for php prepared statement and conditional by the best coders in the world

showing results for - "php prepared statement and conditional"
Roberta
05 Apr 2018
1$conn = getConnection();
2$query = "SELECT first_name, last_name, description, title, message ,font_size , DATE_FORMAT(effective_date,'%h:%i %p %m-%d-%Y')
3          FROM tbl_messages
4          JOIN tbl_authors ON tbl_authors.id_author = tbl_messages.id_author
5          JOIN tbl_locations ON tbl_messages.id_location = tbl_locations.id_location
6          WHERE tbl_messages.id_location = IF(? = 1,tbl_messages.id_location,?)
7          AND effective_date <= NOW()
8          ORDER BY effective_date DESC
9          LIMIT 1
10          ";
11
12if (!$stmt = $conn->prepare($query)) {
13    return false;
14}
15
16$stmt->bind_param('ii', $location,$location);
17
18$result = array();
19
20$stmt->bind_result($first_name, $last_name, $location, $title, $message, $size, $date);
21$stmt->execute();
22
23while ($stmt->fetch()) {
24    $m = new Message($first_name, $last_name, $location, $title, $message, $size, $date);
25    array_push($result, $m);
26}
27
28return $result;
29
similar questions
queries leading to this page
php prepared statement and conditional