Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php prepared statement and conditional

$conn = getConnection();
$query = "SELECT first_name, last_name, description, title, message ,font_size , DATE_FORMAT(effective_date,'%h:%i %p %m-%d-%Y')
          FROM tbl_messages
          JOIN tbl_authors ON tbl_authors.id_author = tbl_messages.id_author
          JOIN tbl_locations ON tbl_messages.id_location = tbl_locations.id_location
          WHERE tbl_messages.id_location = IF(? = 1,tbl_messages.id_location,?)
          AND effective_date <= NOW()
          ORDER BY effective_date DESC
          LIMIT 1
          ";

if (!$stmt = $conn->prepare($query)) {
    return false;
}

$stmt->bind_param('ii', $location,$location);

$result = array();

$stmt->bind_result($first_name, $last_name, $location, $title, $message, $size, $date);
$stmt->execute();

while ($stmt->fetch()) {
    $m = new Message($first_name, $last_name, $location, $title, $message, $size, $date);
    array_push($result, $m);
}

return $result;
Comment

PREVIOUS NEXT
Code Example
Php :: yii form custom label 
Php :: Laravel Direct Browser Download 
Php :: laravel collection load 
Php :: date format in php 
Php :: wordpress curl wp remote post timeout error 
Php :: buddypress groups dropdown 
Php :: Bundling data mvc php 
Php :: type of var php 
Php :: namespace autoload php 
Php :: spring delete objest from database that are not in your object list 
Php :: $user-id show 0 in blade laravel 8 
Php :: laravel eloquent save method return value 
Php :: laravel-filemanager not working 
Php :: dynamic base url 
Php :: php sort array 
Php :: Problems with Special Characters between Angular http post and PHP 
Php :: PHP $argv echo with number of words 
Php :: How to programmatically grab the product description in WooCommerce? 
Php :: pcntl_fork php mysql "MySQL server has gone away" 
Php :: php array merge 
Php :: Lumen framework promise 
Php :: factorial program in php 
Php :: cmb2-repeater video show single page with wordpress 
Php :: selecting a time zone from a drop-down list 
Php :: laravel localrole per many to many 3 foreign 
Php :: nano seed generator 
Php :: Laravel Http client retry request if fail 
Php :: Undefined offset: 0 at laravelframeworksrcIlluminateRoutingRouter.php 
Php :: override CouponPost.php 
Php :: GZIP COMPRESSION With PHP 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =