Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $sessionID=session_id();
- $con = new mysqli(*, *, *, *);
- if (!$con){
- die( print_r("Connect failed: %s\n", mysqli_connect_error()));
- }
- $searchparam=$_GET['search'];
- ?>
- <?php
- $searchparam=str_replace(" ", "+", $searchparam);
- $searchparam="% " . $searchparam . " %";
- $searchparam=str_replace("+", " %+% ", $searchparam);
- $searchquery=explode("+",$searchparam);
- $x=count($searchquery)-1;
- $y=0;
- $paramcount='?';
- $types='s';
- while ($x>$y) {
- $paramcount=$paramcount . ' OR (tags LIKE ?)';
- $types=$types . 's';
- $y++;
- }
- $title=array();
- $author=array();
- $date=array();
- $content=array();
- $tags=array();
- if ($stmt = mysqli_prepare($con, "SELECT title,author,date,content,tags FROM content WHERE tags LIKE " . $paramcount . " ORDER BY count DESC")) {
- array_unshift($searchquery, $stmt, $types);
- call_user_func_array('mysqli_stmt_bind_param',$searchquery);
- mysqli_stmt_execute($stmt);
- mysqli_stmt_bind_result($stmt, $titleFetched, $authorFetched, $dateFetched, $contentFetched, $tagsFetched);
- while (mysqli_stmt_fetch($stmt)) {
- $title[] = $titleFetched;
- $author[] = $authorFetched;
- $date[] = $dateFetched;
- $content[] = $contentFetched;
- $tags[] = $tagsFetched;
- }
- mysqli_stmt_close($stmt);
- }
- $x=0;
- foreach($tags as $tagsun) {
- $tags[$x] = explode(" ", $tags[$x]);
- $x++;
- }
- $x=0;
- foreach ($title as $titledis){
- echo '<div class="blogpost">
- <strong><h1 style="margin-bottom:5px;margin-top:5px;">' . $titledis . '</h1></strong>' . $author[$x] . ' ' . $date[$x];
- echo '<br><br>' . $content[$x] . '<br><br>Tags: '; foreach($tags[$x] as $tagsecho) { echo '<a href="/search.php?search=' . $tagsecho . '">' . $tagsecho . '</a> '; } echo '<br></div>';
- $x++;
- }
- if ($title[0]==$null) {
- echo '<div class="blogpost">
- <strong><h1 style="margin-bottom:5px;margin-top:5px;">No results returned</h1></strong></div>';
- }
- ?>
Add Comment
Please, Sign In to add comment