-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
92 lines (71 loc) · 4.1 KB
/
search.php
File metadata and controls
92 lines (71 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php include "includes/database.php" ?>
<?php include "includes/header.php" ?>
<?php include "includes/navbar.php" ?>
<div class="container py-3 text-break" >
<div class="row">
<section class="col-md-8 all-posts-container py-4" >
<?php
if(isset($_POST['submitsearch'])){
if(empty($_POST['search'])){
redirect("/marvel/");
}else{
$select_option = $_POST['inlineRadioOptions'];
$search = $_POST['search'];
switch($select_option){
case 'option1':
$result=query("SELECT * FROM posts INNER JOIN users ON users.user_id = posts.user_name_id WHERE users.user_name LIKE '$search'");
break;
case 'option2':
$result=query("SELECT * FROM posts INNER JOIN users ON users.user_id = posts.user_name_id WHERE posts.post_title LIKE '$search'");
break;
case 'option3':
$result=query("SELECT * FROM posts INNER JOIN users ON users.user_id = posts.user_name_id WHERE posts.post_tags LIKE '%$search%'");
break;
}
$count = mysqli_num_rows($result);
if($count == 0 ){
echo "<h2 class='text-white text-center'>Search Result: ($count) </h2><hr class='red-line pb-3'>";
echo "<h4 class='text-white text-center py-3'>Sorry, we couldn't find a match for <span class='no-result-color'>$search</span>. Please try another search</h4>";
}else{
echo "<h2 class='text-white text-center'>Search Results: ($count) </h2><hr class='red-line pb-3'>";
while($row = mysqli_fetch_array($result)):
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_subtitle = $row['post_subtitle'];
$post_author = $row['user_name_id'];
$post_image = $row['post_image'];
$post_content = substr($row['post_content'],0,300);
$user_id = $row['user_id'];
$user_name = $row['user_name'];
?>
<h1 class="post-title text-uppercase"><a class="post-title-link no-hover-decoration" href="/marvel/post/<?= $post_id ?>"><?= $post_title ?><br></a>
<span class="post-subtitle"> <?= $post_subtitle ?></span>
</h1>
<div class="div-post-image">
<img class="img-fluid post-image" src="/marvel/public/images/<?= $post_image ?>" alt="">
</div>
<br>
<div class="post-content" >
<p><?= $post_content ?><?php echo strlen($post_content) == 300 ? "...":""; ?></p>
</div>
<div class="row pt-3 px-4">
<div class="col-6 mt-1">
<span class="text-white">By: <a name="user" class="no-hover-decoration post-by-author" href="/marvel/profile/<?= $user_id ?>"> <?= $user_name ?></a></span>
</div>
<div class="col-6 pl-4">
<button class="red-button btn btn-sm float-right" type="button">
<a href="/marvel/post/<?= $post_id ?>" class="readmore-link">Keep Reading <i class="fas fa-chevron-right"></i></a>
</button>
</div>
</div>
<hr class="red-line">
<?php endwhile;
}//if count > 0
}//if search field is not empty
}
?>
</section>
<?php include "includes/sidebar.php"; ?>
</div>
</div>
<?php include "includes/footer.php" ?>