Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4.  
  5. $dbhost     = "localhost";
  6. $dbname     = "sportsDay";
  7. $dbuser     = "root";
  8. $dbpass     = "ITGS!!!";
  9.  
  10. $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
  11.    
  12. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13.    
  14. $conn->exec("SET CHARACTER SET utf8mb4");
  15.  
  16. $result[]=0;
  17.  
  18. foreach ($event as $e) {
  19.   foreach ($gender as $g) {
  20.     foreach ($year as $y) {
  21.       $sql = "SELECT Students.lName, Students.fName, Students.house
  22.  
  23.         FROM Entries INNER JOIN Events ON Entries.ev1ID = Events.ID
  24.  
  25.         JOIN Students ON Students.stID = Entries.stID
  26.  
  27.         WHERE (Entries.ev1ID = :event or Entries.ev2ID = :event2) and (Students.year = :year)
  28.         AND (Students.gender = :gender)
  29.  
  30.         ORDER BY Students.house ASC"; // Query stays the same.
  31.  
  32.         $stmt->bindValue(':event', $e);
  33.         $stmt->bindValue(':event2', $e);
  34.         $stmt->bindValue(':year', $y);
  35.         $stmt->bindValue(':gender', $g);
  36.         // Use $e, $g and $y for your query and table construction.
  37.         $result[]=0;
  38.         try
  39.         {
  40.    
  41.    
  42.  
  43.    
  44.    
  45.  
  46.     $stmt = $conn->prepare($sql);
  47.  
  48.     $stmt->bindValue(':event', $e);
  49.     $stmt->bindValue(':event2', $e);
  50.     $stmt->bindValue(':year', $y);
  51.     $stmt->bindValue(':gender', $g);
  52.  
  53.     $stmt->execute();
  54.    
  55.     $result = $stmt->fetchAll();
  56.  
  57.     $count = $stmt->rowCount();
  58.  
  59. }
  60.  
  61. catch(PDOException $e)
  62. {
  63.     echo $e->getMessage();
  64. }
  65.      ?>
  66.      
  67.      
  68.      
  69.      <html>
  70.      <head>
  71.      <style type="text/css">
  72.      table{
  73.         width: 85%;  
  74.         margin-left: 2%;
  75.      }
  76.      
  77.      th, td{
  78.          padding: 5px 25px 5px 25px;
  79.      }
  80.      
  81.      </style>
  82.      <body>
  83.      <?php if ($count > 0): ?>
  84.     <table border="1" >
  85.         <tr>
  86.             <th>Name</th>
  87.             <th>House</th>
  88.             <th>Score</th>
  89.         </tr>
  90.         <?php foreach ($result as $row) {
  91.             ?>
  92.         <tr>
  93.             <td><?php echo $row['fName']. ' '.$row['lName'] ?></td>
  94.             <td><?php echo $row['house'] ?></td> <td></td>
  95.         </tr>
  96.         <?php } ?>
  97.     </table>
  98. <?php else: echo "No results.";
  99. endif;
  100.         }
  101.     }
  102.   } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement