Skip to content

Commit

Permalink
upgrade: show user image in posts
Browse files Browse the repository at this point in the history
  • Loading branch information
didof committed Jan 17, 2020
1 parent 6e859e5 commit 5433c3c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 29 deletions.
106 changes: 80 additions & 26 deletions includes/showPost.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,88 @@

$userId = $_SESSION["userId"];

$sql = "SELECT * FROM post ORDER BY post_date DESC";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query) > 0) {
while ($row = mysqli_fetch_assoc($query)) {
echo '<div class="post">
if (isset($_POST["search-submit-post"])) {
$searchInput = $_POST["searchInput"];
$sql = "SELECT * FROM post
JOIN profileimg ON post.post_user_id = profileimg.userId
WHERE post_title LIKE ?
OR post_author LIKE ?
OR post_date LIKE ?
OR post_dir LIKE ?
ORDER BY post_date DESC";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
$searchCirca = "%{$searchInput}%";
mysqli_stmt_bind_param($stmt, "ssss", $searchCirca, $searchCirca, $searchCirca, $searchCirca);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (is_null($result)) {
echo 'There was no result for <i> ' . $searchInput . '</i>. Try with the title or the
author or the data or the directory.';
} else {
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="post">
<div class="header">
<div><img src="uploads/' . $row["name"] . '" height="40px" width="40px"></div>
<div>' . $row["post_title"] . '</div>
<div>' . $row["post_author"] . ' (' . $row["post_user_id"] . ')</div>';
if ($userId == $row["post_user_id"]) {
echo '<div><button>Modify</button></div>
if ($userId == $row["post_user_id"]) {
echo '<div><button>Comment</button></div>
<div><button>Modify</button></div>
<div><a href="includes/deletePost.inc.php?idPost=' . $row["id"] . '"><button>Cancel</button></a></div>';
} else {
echo '<div></div>
<div></div>';
}
echo '</div>'; // close class header
echo '<div class="content">';
if ($row["post_file_name"] == "") {
} else {
$imageAuthor = $row["post_author"];
$imageDir = $row["post_dir"];
$imageName = $row["post_file_name"];
$imagePath = "uploads/post/" . $imageDir . "/" . $imageAuthor . "/" . $imageName;
echo '<img src="' . $imagePath . '" width="100px" height="100px">';
}
echo $row["post_content"] . '<br><br>';
echo '<i>Posted on ' . $row["post_date"] . ' in /' . $row["post_dir"];
} // close while loop
}
} else {
$sql = "SELECT * FROM post
JOIN profileimg ON post.post_user_id = profileimg.userId
ORDER BY post_date DESC";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query) > 0) {
while ($row = mysqli_fetch_assoc($query)) {
echo '<div class="post">
<div class="header">
<div><img src="uploads/' . $row["name"] . '" height="40px" width="40px"></div>
<div>' . $row["post_title"] . '</div>
<div>' . $row["post_author"] . ' (' . $row["post_user_id"] . ')</div>';
if ($userId == $row["post_user_id"]) {
echo '<div><button>Comment</button></div>
<div><button>Modify</button></div>
<div><a href="includes/deletePost.inc.php?idPost=' . $row["id"] . '"><button>Cancel</button></a></div>';
} else {
echo '<div></div>
} else {
echo '<div></div>
<div></div>';
}
echo '</div>'; // close class header
echo '<div class="content">';
if ($row["post_file_name"] == "") {
} else {
$imageAuthor = $row["post_author"];
$imageDir = $row["post_dir"];
$imageName = $row["post_file_name"];
$imagePath = "uploads/post/" . $imageDir . "/" . $imageAuthor . "/" . $imageName;
echo '<img src="' . $imagePath . '" width="100px" height="100px">';
}
echo $row["post_content"] . '<br><br>';
echo '<i>Posted on ' . $row["post_date"] . ' in /' . $row["post_dir"];
} // close if not set picture
echo '</div>'; // close class content
echo '</div>'; // close this post
} // close while
}
echo '</div>'; // close class header
echo '<div class="content">';
if ($row["post_file_name"] == "") {
} else {
$imageAuthor = $row["post_author"];
$imageDir = $row["post_dir"];
$imageName = $row["post_file_name"];
$imagePath = "uploads/post/" . $imageDir . "/" . $imageAuthor . "/" . $imageName;
echo '<img src="' . $imagePath . '" width="100px" height="100px">';
}
echo $row["post_content"] . '<br><br>';
echo '<i>Posted on ' . $row["post_date"] . ' in /' . $row["post_dir"];
echo '</div>'; // close class content
echo '</div>'; // close this post
} // close while loop

} // close while
}
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<div class="searchBar">
<form action="index.php" method="post">
<input type="text" name="searchInput" placeholder="Look for an username/e-mail">
<button type="submit" name="search-submit">Search</button>
<button type="submit" name="search-submit">Search user</button>
<button type="submit" name="search-submit-post">Search post</button>
</form>
</div>
<div class="profilePic">
Expand Down
4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ button:disabled {

.post .header {
display: grid;
grid-template-columns: 3fr 3fr 1fr 1fr;
grid-template-columns: 1fr 2fr 2fr 1fr 1fr 1fr;
background-color: #46424b;
font-size: 20px;
font-family: Arial;
color: white;
padding: 3px 5px;
border-radius: 5px;
height: 40px;
height: 50px;
}

.profile-pic {
Expand Down

0 comments on commit 5433c3c

Please sign in to comment.