Fixed queries and profile page.

This commit is contained in:
K. Nobel
2017-01-19 12:01:39 +01:00
parent b37d06e2cc
commit 84719529bb
5 changed files with 20 additions and 18 deletions

View File

@@ -46,12 +46,12 @@ if(empty($_GET["username"])) {
return;
}
$userID = getUserID($db, $_GET["username"]);
$userID = getUserID($_GET["username"]);
$user = selectUser($db, $userID);
$friends = selectAllFriends($db, $userID);
$groups = selectAllUserGroups($db, $userID);
$posts = selectAllUserPosts($db, $userID);
$user = selectUser($userID);
$profile_friends = selectAllFriends($userID);
$profile_groups = selectAllUserGroups($userID);
$posts = selectAllUserPosts($userID);
?>

View File

@@ -1,7 +1,7 @@
<?php
require("connect.php");
function selectAllFriends($db, $userID) {
function selectAllFriends($userID) {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`username`,

View File

@@ -1,8 +1,8 @@
<?php
require("connect.php");
function getUserID($db, $username) {
$stmt = $db->prepare("
function getUserID($username) {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`userID`
FROM
@@ -16,8 +16,8 @@ function getUserID($db, $username) {
return $stmt->fetch()["userID"];
}
function selectUser($db, $userID) {
$stmt = $db->prepare("
function selectUser($userID) {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`username`,
IFNULL(
@@ -41,7 +41,7 @@ function selectUser($db, $userID) {
return $stmt->fetch();
}
function selectAllUserGroups($db, $userID) {
function selectAllUserGroups($userID) {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`group_page`.`groupID`,
@@ -64,7 +64,7 @@ function selectAllUserGroups($db, $userID) {
return $stmt;
}
function selectAllUserPosts($db, $userID) {
function selectAllUserPosts($userID) {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`postID`,

View File

@@ -13,7 +13,7 @@
$_SESSION["userID"] = 2;
// Get all the friends of a user.
$friends = selectAllFriends($db, $_SESSION["userID"]);
$friends = selectAllFriends($_SESSION["userID"]);
$i = 0;
// Print all the users.

View File

@@ -4,18 +4,19 @@
<div class="profile-button">
<p><img src="img/add-friend.png"> Als vriend toevoegen</p>
</div>
<h1 class="profile-username"><?php echo $user["username"] ?></h1>
<p><?php echo $user["bio"] ?></p>
<h1 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?> (<?=$user["username"]?>)</h1>
<p><?=$user["bio"]?></p>
</div>
<div class="item-box left platform">
<h2>Vrienden</h2>
<p>
<?php
while($friend = $friends->fetch()) {
echo "<a href='#' data-title='" . $friend["username"] . "'><img class='profile-picture' src='" . $friend["profilepicture"] . "' alt='" . $friend["username"] . "'s profielfoto></a>";
while($friend = $profile_friends->fetch()) {
echo "<a href='#' data-title='${friend["username"]}'><img class='profile-picture' src='${friend["profilepicture"]}' alt='${friend["username"]}'s profielfoto></a>";
}
if($friends->rowCount() === 0) {
echo "<p>Deze gebruiker heeft nog geen vrienden gemaakt.</p>";
}
@@ -27,7 +28,7 @@
<h2>Groepen</h2>
<p>
<?php
while($group = $groups->fetch()) {
while($group = $profile_groups->fetch()) {
echo "<a href='#' data-title='${group["name"]}'><img class='group-picture' src='${group["picture"]}' alt='${group["name"]}s logo'></a>";
}
@@ -52,3 +53,4 @@
}
?>
</div>
</div>