Guest User

Untitled

a guest
Feb 26th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. // Koneksi.php
  2.  
  3. <?php
  4. class Koneksi {
  5. private $SERVER = "localhost";
  6. private $DATABASE = "contoh_test";
  7. private $USERNAME = "root";
  8. private $PASSWORD = "";
  9. private $koneksi;
  10. public function __construct() {
  11. try {
  12. $dsn = "mysql:host=" . $this->SERVER . ";port=3307;dbname=" . $this->DATABASE;
  13. $this->koneksi = new PDO($dsn, $this->USERNAME, $this->PASSWORD);
  14. } catch (PDOException $e) {
  15. echo $e->getMessage();
  16. }
  17. }
  18. function getKoneksi() {
  19. return $this->koneksi;
  20. }
  21. }
  22. ?>
  23.  
  24. //----------------------------------------------------------------------------------------
  25.  
  26. // Pohon.php
  27.  
  28. <?php
  29.  
  30. include_once 'koneksi.php';
  31.  
  32. $countSameLevel = 0;
  33. $res = false;
  34.  
  35. function getByUser($uid) {
  36. $db = new Koneksi();
  37. $koneksi = $db->getKoneksi();
  38. $sql = "SELECT * FROM user where id=$uid";
  39. $con = $koneksi->prepare($sql);
  40. $con->execute();
  41. return $con->fetchAll();
  42. }
  43.  
  44. function getUpline($uid) {
  45. $db = new Koneksi();
  46. $koneksi = $db->getKoneksi();
  47. $sql = "SELECT * FROM user where upline=$uid";
  48. $con = $koneksi->prepare($sql);
  49. $con->execute();
  50. return $con->fetchAll();
  51. }
  52.  
  53. function countLevel($upline, $level) {
  54. $db = new Koneksi();
  55. $koneksi = $db->getKoneksi();
  56. $sql = "SELECT * FROM user where upline=$upline AND level=$level";
  57. $con = $koneksi->prepare($sql);
  58. $con->execute();
  59. return $con->rowCount();
  60. }
  61.  
  62. echo "<ul>";
  63. foreach (getByUser(1) as $row) {
  64. echo "<li>" . $row['name'] . "(" . $row['level'] . ")" . "</li>";
  65. echo "<ul>";
  66. foreach (getUpline($row['id']) as $upline) {
  67. echo "<li>" . $upline['name'] . "(" . $upline['level'] . ")" . "</li>";
  68. if (!$res) {
  69. if (countLevel(1, $upline['level']) >= 3) {
  70. $res = true;
  71. }
  72. }
  73. }
  74. echo "</ul>";
  75. }
  76. echo "</ul>";
  77.  
  78. echo "dapat bonus?\n";
  79. if ($res) {
  80. echo "<br>dapet<br>";
  81. } else {
  82. echo "<br>nggak<br>";
  83. }
  84.  
  85. ?>
Add Comment
Please, Sign In to add comment