Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. WIEW
  2.  
  3.  
  4. <?php
  5. require_once("./controller/controller.php");
  6. ?>
  7. <!doctype html>
  8. <html>
  9. <head>
  10. <meta charset="utf-8" />
  11. </head>
  12. <body>
  13. sprawdzanie liczb:<br />
  14. <table border='1' ><tr>
  15. <th> lp </th>
  16. <th> liczba 1</th>
  17. <th> liczba 2 </th>
  18. <th> Czy podzielna? </th>
  19.  
  20.  
  21. <?php $check->getCheck(); ?>
  22. </tr></table>
  23. </body>
  24. </html>
  25.  
  26.  
  27. MODEL
  28.  
  29.  
  30. <?php
  31. class Connect{
  32. private $host = "localhost";
  33. private $db = "matematyka";
  34. private $user = "root";
  35. private $password = "";
  36.  
  37. public function setConnect($host, $db, $user, $password){
  38. $this->host = $host;
  39. $this->db = $db;
  40. $this->user = $user;
  41. $this->password = $password;
  42. }
  43.  
  44. public function getConnect(){
  45. return $conn = new PDO('mysql:host='.$this->host.';dbname='.$this->db.'',$this->user,$this->password);
  46. }
  47.  
  48. }
  49.  
  50. class QueryDB extends Connect{
  51. private $result;
  52.  
  53. public function setQueryDB($result, $obj){
  54. $this->result = $result;
  55. }
  56.  
  57. public function getQueryDB(){
  58. $this->result = $this->getConnect()->query("SELECT * FROM liczby");
  59. return $this->obj = $this->result -> fetchAll(PDO::FETCH_OBJ);
  60. }
  61. }
  62. ?>
  63.  
  64. TO TEN ZE ZDJECJA
  65.  
  66. CONTROLER
  67. <?php
  68. require_once("./model/model.php");
  69. class Check extends QueryDB{
  70.  
  71. public function getCheck(){
  72.  
  73. $lp=1;
  74.  
  75. foreach($this->getQueryDB() as $value){
  76. echo "<tr>";
  77. if($value->a % $value->b == 0){
  78. echo "<tr bgcolor ='green'>";
  79. echo "<td>".$lp." </td>";
  80. echo "<td>".$value->a." </td>";
  81. echo "<td>".$value->b. "</td>";
  82. if($value->a % 2 == 0 || $value->b % 2 == 0)
  83. echo "<td><b>TAK</b></td>";
  84. else
  85. echo "<td>TAK</td>";
  86. echo "</tr>";
  87. }else { echo "<tr bgcolor ='red'>";
  88. echo "<td >".$lp."</td>";
  89. echo "<td>".$value->a." </td>";
  90. echo "<td>".$value->b. "</td>";
  91. if($value->a % 2 == 0 || $value->b % 2 == 0)
  92. echo "<td><b>NIE</b></td>";
  93. else
  94. echo "<td>NIE</td>";
  95. echo "</tr>";
  96.  
  97.  
  98. }
  99. echo "</tr>";
  100. $lp++;
  101. }
  102.  
  103. }
  104. }
  105.  
  106. $check = new Check;
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement