Created
June 7, 2017 15:05
-
-
Save ikushlianski/fc1eb183c8e5935da69cf73f00476da0 to your computer and use it in GitHub Desktop.
AJAX + PHP retrieving from DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$connection = mysqli_connect('127.0.0.1', 'root', '', 'uefa_teams'); | |
// Check connection | |
if (!$connection) { | |
die("Connection failed: " . mysqli_connect_error()); | |
} | |
if (isset($_GET['selectAllUEFAClubs'])) { | |
$selectAllUEFAClubs = $connection->query("SELECT * FROM clubs"); | |
if ($selectAllUEFAClubs -> num_rows > 0) { | |
while($row = $selectAllUEFAClubs->fetch_assoc()) { | |
$team = ["club_name" => $row['club_name'], "club_country" => $row['club_country'], "club_ranking" => $row['club_ranking'], "club_logo_url" => $row['club_logo']]; | |
$allTeamsFetched[] = $team; | |
} | |
echo json_encode($allTeamsFetched); | |
} | |
} | |
if (isset($_GET['selectAllUEFANations'])) { | |
$selectAllUEFANations = $connection->query("SELECT nation_name FROM member_associations"); | |
if ($selectAllUEFANations -> num_rows > 0) { | |
while($row = $selectAllUEFANations->fetch_assoc()) { | |
$team = ["nation_name" => $row['nation_name']]; | |
$allNationsFetched[] = $team; | |
} | |
echo json_encode($allNationsFetched); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.min.js" | |
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | |
crossorigin="anonymous"></script> | |
<script src="test.js" charset="utf-8"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// all classes | |
class Uefa { | |
constructor() { | |
this.fetchAllUEFATeams(); | |
} | |
// fetch all clubs from complete UEFA list for further draw | |
fetchAllUEFATeams() { | |
$.ajax({ | |
url: 'functions.php?selectAllUEFAClubs', | |
type: 'GET', | |
success: function(res) { | |
console.log(JSON.parse(res)); | |
} | |
}); | |
} | |
// fetchAllUEFANations() { | |
// $.ajax({ | |
// url: 'functions.php?selectAllUEFANations', | |
// type: 'GET', | |
// success: function(res) { | |
// console.log(JSON.parse(res)); | |
// } | |
// }); | |
// }; | |
} | |
var championsLeague = { | |
allSeasonParticipants: [], | |
determineSeasonParticipants() { | |
// fetch all participants on client | |
}, | |
firstQualRound_participants: [], | |
determineFirstQualRoundParticipants() { | |
}, | |
secondQualRound_participants: [], | |
determineSecondQualRoundParticipants() { | |
}, | |
thirdQualRound_participants: [], | |
determineThirdQualRoundParticipants() { | |
}, | |
qualificationPlayoff_participants: [], | |
determineQualPlayoffParticipants() { | |
}, | |
groupStage_participants: [], | |
determineGroupStage_participants(){ | |
} | |
} | |
// initialize app | |
var uefa = new Uefa; | |
const ELCHAMPION = ["Manchester United"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment