<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="form.css">
  <link rel="stylesheet" href="table.css">
  <link rel="stylesheet" href="main.css">
  <title>View all Attendees</title>
  <link rel="stylesheet" href="table.css">
</head>
<body>
<?php

require 'databasebac.php';
$memberName = $_POST['memberName'];




// echo "Haha.. Connected successfully";
$sql = "SELECT * FROM `thites` WHERE `member` = '$memberName'";
$sql2 = "SELECT SUM(ThithesAmount) AS Total_Thithes FROM `thites` WHERE `member` = '$memberName'";

$results = mysqli_query($con, $sql);
$results2 = mysqli_query($con, $sql2);

// srtatement for all thites amount based on name
if ($results === false) {
  // code...
  echo mysqli_error($con);
} else {

//    
  // code...
  $viewThites= mysqli_fetch_all($results, MYSQLI_ASSOC );
  // read all amount from that name then sum them


  
}




// statement for total thites
// if ($results2->num_rows > 0) {
//     while($row = $results2->fetch_array()) {
//         $sum = $row['Total_Thithes'];
//         echo "$sum)";
//     }
//  }
//  else 
//     echo "no thites for this user";



$row = $results2->fetch_array();
$sum = $row['Total_Thithes'];
echo $sum;

?>

  <?php require '../includes/header.php'; ?>
    
       <?php if (empty($viewThites)):?>
         <p>No Amount found</p>
       <?php else: ?>
       
        <p>List of Thites for <?php echo $_POST['memberName']; ?> </p>
         <?php foreach ($viewThites as $thites):  ?>
           
<?php 

echo "<table>
<tr>
             <th>Name</th>
             <th> Amount</th>
             <th> Date</th>;
           </tr>";
           echo "<tr>";
           echo "<td>".$thites['member'] . "</td>";
           echo "<td>".$thites['ThithesAmount'] . "</td>";
           echo "<td>".$thites['ThithesDate'] . "</td>";

           echo "</tr>";

           echo "</table>"
           
            
            ?>
           
       <?php endforeach; ?>
       </ul>
      <div class="total">
     <p class="total">The total is: $<?php echo $sum; ?> for the year</p>
        
     </div> <div>
        <a href="">print thites statement letter</a>
     </div>
     <?php endif; ?> 
<br>
     

     <?php require 'footer.php' ?>

     
<div><button id="letter">View letter</button></div>

<script>
  $(document).ready(function(){
    $("#letter").click(function(){
      $.post("")
    })
  })
</script>
 
     <div onClick="history.back()">Go back</div>

    

</body>
</html>
