daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <body>
  5.  
  6. <form method="post">
  7. <!--
  8. Year: <input type="text" name="year"><br>
  9. -->
  10. Choose a date: <input type="number" name="year">
  11. Total or average salary:<br>
  12.  
  13. <select name="option">
  14.     <option value="total">Total</option>
  15.     <option value="average">Average</option>
  16. </select>
  17. <input type="submit">
  18. </form>
  19.  
  20. <?php
  21. $servername = "localhost";
  22. $username = "root";
  23. $password = "root";
  24. $dbname = "employees";
  25.  
  26. // Create connection
  27. $conn = new mysqli($servername, $username, $password, $dbname);
  28.    
  29.     if(!$conn){
  30.         exit("Error: could not reach database.");
  31.     }
  32. // Check connection
  33. if ($conn->connect_error) {
  34.     die("Connection failed: " . $conn->connect_error);
  35. }
  36.  
  37.    
  38.  
  39. // $year = $_POST['year']
  40. $year = $_POST['year'];
  41. $option = $_POST['option'];
  42.    
  43. if($option == 'total'){
  44.     $sql = "SELECT COUNT(s.salary) AS salary
  45.             FROM salaries AS s
  46.             WHERE $year = LEFT(s.from_date,4)";
  47. }
  48.  
  49.  
  50. $resultat = mysqli_query($conn, $sql);
  51.  
  52. print('<table border="1">');
  53. $rad = mysqli_fetch_assoc($resultat);
  54. if ($resultat->num_rows > 0) {
  55.     while($rad){
  56.         $salary=$rad['salary'];
  57.    
  58.         echo ("<tr><td>$salary  </td></tr>");
  59.         $rad = mysqli_fetch_assoc($resultat);
  60.     }
  61.     }else {
  62.         echo "0 results.";
  63.     }
  64.     print('</table>');
  65.  
  66.     mysqli_close($conn);
  67.    
  68. ?>
  69.  
  70.  
  71.     </body>
  72. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top