Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. <?php
  2.  
  3. function dbConnect() //function database connect
  4. {
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. $dbname = "dc_heroes";
  9.  
  10. //variable for the database connections error message if there is no connection
  11. $conn = mysqli_connect($servername, $username, $password, $dbname) or die(mysqli_error($conn));
  12.  
  13. return $conn;
  14. }
  15.  
  16.  
  17. function getTeams() // fucntion team display
  18. {
  19. //connect to database
  20. $conn = dbConnect();
  21.  
  22. //define an empty array to store teams
  23. $teams = array();
  24.  
  25. //define the query to fetch data from the database
  26. $getTeamsSQL = "SELECT * FROM `teams` ORDER BY `teamId` ASC";
  27.  
  28.  
  29. //perform query on $conn and store resource
  30. $resource = mysqli_query($conn, $getTeamsSQL) or die(mysqli_error($conn));
  31.  
  32. while($row = mysqli_fetch_assoc($resource))//gives an associative array and puts it in teams
  33. {
  34. //add new items to $teams
  35. $teams[] = $row;
  36. }
  37.  
  38. return $teams;
  39. }
  40.  
  41.  
  42. function getHero() //function hero card display
  43. {
  44. //connect to database
  45. $conn = dbConnect();
  46.  
  47. if(isset($_GET["teamId"])) //checks in the url of teamId exists, it is declared and different then NULL
  48. {
  49. $teamId = $_GET["teamId"]; //Hyperlink to the products page using a GET parameter
  50. }
  51. else
  52. {
  53. $teamId = 1;
  54. }
  55.  
  56. //define the query to fetch data from the database
  57. $getHeroSQL = "SELECT * FROM `characters`, `teams` WHERE `teams` .`teamId` = `characters` .`teamId`";
  58.  
  59. if(isset($teamId) && $teamId != "") //!= means it cant be equal""
  60. {
  61. $getHeroSQL.= " AND `teams` .`teamId` = ".$teamId.""; //if we have a category id it will add it to our if statement
  62. }
  63.  
  64. //perform query on $conn and store resource
  65. $resource = mysqli_query($conn, $getHeroSQL);
  66.  
  67. while($row = mysqli_fetch_assoc($resource))//gives an associative array and puts it in teams
  68. {
  69. //add new items to $teams
  70. $Heroes[] = $row;
  71. }
  72.  
  73. return $Heroes;
  74. }
  75.  
  76. function getHeroInfo()
  77. {
  78. //connect to database
  79. $conn = dbConnect();
  80.  
  81. if(isset($_GET["teamId"])) //checks in the url of teamId exists, it is declared and different then NULL
  82. {
  83. if(isset($_GET["characterId"]))
  84. {
  85. $teamId = $_GET["teamId"];
  86. $characterId = $_GET["characterId"];
  87. }
  88. }
  89. else
  90. {
  91. $teamId = 1;
  92. $characterId = 1;
  93. }
  94.  
  95. //define the query to fetch data from the database
  96. $getHeroInfoSQL = "SELECT * FROM `characters` WHERE `characters` .`characterId`";
  97.  
  98. if(isset($teamId) && $teamId != "" && isset($characterId) && $characterId != "") //!= means it cant be equal""
  99. {
  100. $getHeroInfoSQL.= "AND `characters`.`characterId` = ".$characterId.""; //if we have a category id it will add it to our if statement
  101. }
  102.  
  103. $resource = mysqli_query($conn, $getHeroInfoSQL) or die(mysqli_error($conn));
  104. $heroInfo = mysqli_fetch_array($resource);
  105.  
  106.  
  107. return $heroInfo;
  108.  
  109. }
  110.  
  111. function getPowers()
  112. {
  113. //connect to database
  114. $conn = dbConnect();
  115.  
  116. //define an empty array to store powers
  117. $powers = array();
  118.  
  119. if(isset($_GET["teamId"])) //checks in the url of teamId exists, it is declared and different then NULL
  120. {
  121.  
  122. if(isset($_GET["characterId"]))
  123. {
  124. $teamId = $_GET["teamId"];
  125. $characterId = $_GET["characterId"];
  126. }
  127. }
  128. else
  129. {
  130. $teamId = 1;
  131. $characterId = 1;
  132. }
  133.  
  134. //sql statement to fetch the powers
  135. $getPowerSQL = "SELECT `propertyText` FROM `properties`, `characterproperties`
  136. WHERE `properties`. `propertyId` = `characterproperties` . `propertyId`";
  137.  
  138. if(isset($teamId) && $teamId != "" && isset($characterId) && $characterId != "") //!= means it cant be equal""
  139. {
  140. $getPowerSQL.= "AND `characterproperties`.`characterId` = ".$characterId.""; //if we have a category id it will add it to our if statement
  141. }
  142.  
  143. //perform query on $conn and store resource
  144. $resource = mysqli_query($conn, $getPowerSQL);
  145.  
  146. while($row = mysqli_fetch_assoc($resource))//gives an associative array and puts it in powers
  147. {
  148. //add new items to $powers
  149. $powers[] = $row;
  150. }
  151.  
  152. return $powers;
  153. }
  154.  
  155. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement