Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "database_ps";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT (COALESCE(a.price, 0) - COALESCE(f.price, 0)) AS total_price FROM tblcustomer c LEFT JOIN (SELECT CustomerID, SUM(Price) as price FROM tblappointment GROUP BY CustomerID ) a ON a.CustomerID = c.CustomerID LEFT JOIN (SELECT CustomerID, SUM(Price) as price FROM tblfinances GROUP BY CustomerID ) f ON f.CustomerID = c.CustomerID where c.CustomerID=3");
- $stmt->execute();
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- }
- catch(PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- echo $result;
- $conn = null;
- ?>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "database_ps";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT (COALESCE(a.price, 0) - COALESCE(f.price, 0)) AS total_price FROM tblcustomer c LEFT JOIN (SELECT CustomerID, SUM(Price) as price FROM tblappointment GROUP BY CustomerID ) a ON a.CustomerID = c.CustomerID LEFT JOIN (SELECT CustomerID, SUM(Price) as price FROM tblfinances GROUP BY CustomerID ) f ON f.CustomerID = c.CustomerID where c.CustomerID=3");
- $stmt->execute();
- $result = $stmt->fetch(PDO::FETCH_ASSOC);
- }
- catch(PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- echo $fetch["total_price"];
- $conn = null;
- ?>
Add Comment
Please, Sign In to add comment