Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function dbConnect() //function database connect
- {
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "dc_heroes";
- //variable for the database connections error message if there is no connection
- $conn = mysqli_connect($servername, $username, $password, $dbname) or die(mysqli_error($conn));
- return $conn;
- }
- function getTeams() // fucntion team display
- {
- //connect to database
- $conn = dbConnect();
- //define an empty array to store teams
- $teams = array();
- //define the query to fetch data from the database
- $getTeamsSQL = "SELECT * FROM `teams` ORDER BY `teamId` ASC";
- //perform query on $conn and store resource
- $resource = mysqli_query($conn, $getTeamsSQL) or die(mysqli_error($conn));
- while($row = mysqli_fetch_assoc($resource))//gives an associative array and puts it in teams
- {
- //add new items to $teams
- $teams[] = $row;
- }
- return $teams;
- }
- function getHero() //function hero card display
- {
- //connect to database
- $conn = dbConnect();
- if(isset($_GET["teamId"])) //checks in the url of teamId exists, it is declared and different then NULL
- {
- $teamId = $_GET["teamId"]; //Hyperlink to the products page using a GET parameter
- }
- else
- {
- $teamId = 1;
- }
- //define the query to fetch data from the database
- $getHeroSQL = "SELECT * FROM `characters`, `teams` WHERE `teams` .`teamId` = `characters` .`teamId`";
- if(isset($teamId) && $teamId != "") //!= means it cant be equal""
- {
- $getHeroSQL.= " AND `teams` .`teamId` = ".$teamId.""; //if we have a category id it will add it to our if statement
- }
- //perform query on $conn and store resource
- $resource = mysqli_query($conn, $getHeroSQL);
- while($row = mysqli_fetch_assoc($resource))//gives an associative array and puts it in teams
- {
- //add new items to $teams
- $Heroes[] = $row;
- }
- return $Heroes;
- }
- function getHeroInfo()
- {
- //connect to database
- $conn = dbConnect();
- if(isset($_GET["teamId"])) //checks in the url of teamId exists, it is declared and different then NULL
- {
- if(isset($_GET["characterId"]))
- {
- $teamId = $_GET["teamId"];
- $characterId = $_GET["characterId"];
- }
- }
- else
- {
- $teamId = 1;
- $characterId = 1;
- }
- //define the query to fetch data from the database
- $getHeroInfoSQL = "SELECT * FROM `characters` WHERE `characters` .`characterId`";
- if(isset($teamId) && $teamId != "" && isset($characterId) && $characterId != "") //!= means it cant be equal""
- {
- $getHeroInfoSQL.= "AND `characters`.`characterId` = ".$characterId.""; //if we have a category id it will add it to our if statement
- }
- $resource = mysqli_query($conn, $getHeroInfoSQL) or die(mysqli_error($conn));
- $heroInfo = mysqli_fetch_array($resource);
- return $heroInfo;
- }
- function getPowers()
- {
- //connect to database
- $conn = dbConnect();
- //define an empty array to store powers
- $powers = array();
- if(isset($_GET["teamId"])) //checks in the url of teamId exists, it is declared and different then NULL
- {
- if(isset($_GET["characterId"]))
- {
- $teamId = $_GET["teamId"];
- $characterId = $_GET["characterId"];
- }
- }
- else
- {
- $teamId = 1;
- $characterId = 1;
- }
- //sql statement to fetch the powers
- $getPowerSQL = "SELECT `propertyText` FROM `properties`, `characterproperties`
- WHERE `properties`. `propertyId` = `characterproperties` . `propertyId`";
- if(isset($teamId) && $teamId != "" && isset($characterId) && $characterId != "") //!= means it cant be equal""
- {
- $getPowerSQL.= "AND `characterproperties`.`characterId` = ".$characterId.""; //if we have a category id it will add it to our if statement
- }
- //perform query on $conn and store resource
- $resource = mysqli_query($conn, $getPowerSQL);
- while($row = mysqli_fetch_assoc($resource))//gives an associative array and puts it in powers
- {
- //add new items to $powers
- $powers[] = $row;
- }
- return $powers;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement