PHP MySQL If Statement with IS NOT NULL Example
Feb 02, 2022 . Admin
Hello Friends,
This article will give you example of php if statement with is not null example. I explained simply about if statement with is not null in php. This tutorial will give you example of php if statement with is not null.
In this post, You'll learn use how to use if statement with is not null in php. i will show you use of if statement with is not null in php.
Here i will give you many example for php if statement with is not null.
Table: user_paymentsSo, let's see bellow solution:
index.php<?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "db_php"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); $sql = "SELECT id, user_id, CASE WHEN charge IS NOT NULL THEN charge ELSE 0 END as charge, payment_date FROM `user_payments`"; $result = $conn->query($sql); while ($row = $result->fetch_assoc()) { echo '<pre>'; print_r($row); } ?>Output:
Array ( [id] => 1 [user_id] => 1 [charge] => 50 [payment_date] => 2022-02-01 ) Array ( [id] => 2 [user_id] => 2 [charge] => 45 [payment_date] => 2022-02-01 ) Array ( [id] => 3 [user_id] => 3 [charge] => 0 [payment_date] => 2022-02-01 ) Array ( [id] => 4 [user_id] => 4 [charge] => 10 [payment_date] => 2022-02-01 )It will help you...