NOTE: Ignore the includes they aren't necessary for what I need help with but Hey guys I i'm going to post the code here then and I have a link you guys can visit to understand this better this is an option. THE LINK OK here it goes.
//The index file
<DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="si_search.php" method="GET">
<input type="text" name="q" dir="ltr">
<input type="submit" value="go">
</form>
</body>
</html>
//The Search script file
<?php
$conn = mysqli_connect("localhost","1234user","1234pw","1234db");
$output = ' ';
if(isset($_GET['q']) && $_GET['q'] !== ' ') {
$searchq = $_GET['q'];
$searchq = trim(" $searchq ");
$searchq = preg_replace('/\s+/', ' ', $searchq);
$searchq = mysqli_real_escape_string($conn, $searchq);
$searchq = htmlspecialchars($searchq);
if ($searchq === "") {
header('Location: '.$_SERVER['PHP_SELF']);
die;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>
Results
</title>
<style>
</style>
</head>
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/results/desktop.css">
<link rel="stylesheet" type="text/css" href="css/results/mobile.css">
<body>
<!-- loading Screen -->
<?php include("loading_screen.php"); ?>
<!-- Search Bar -->
<?php include "index.php"; ?>
<?php
$q = mysqli_query($conn, "SELECT * FROM search_i WHERE keywords LIKE '%$searchq%' OR title LIKE '%$searchq%' ORDER BY title DESC") or die(mysqli_error());
$c = mysqli_num_rows($q);
if($c == 0) {
$output = '<h2 class="no_results_error_message";><span style="color: red;">No results for:</span><b>"<span style="color: white;">' . $searchq . '</span></h2>"</b>';
} else {
?>
<div class="result_section";>
<h2><span class="for_headline">Results For: </span><span id="result_output"><?php $outputx = "$searchq"; print("$outputx"); ?></span></h2>
</div>
<div class="box_template";>
<?php
while($row = mysqli_fetch_array($q)) {
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$images = $row['images'];
?>
<div class="image_and_title_box";>
<div class="image_box";>
<a href="<?php echo $row['link']; ?>"><img id="image_content_inside_box" src="<?php echo $row['images']; ?>"> </a>
</div>
<div class="box_general_text";>
<h2 class="box_title"> <a href="<?php echo $row['link']; ?>"><?php echo $row['title']; ?>
</a>
</h2>
<div>
</div>
<div class="external_box_paragraph";>
<p id="box_paragraph_content";><?php echo $row['description']; ?></p>
</div>
</div>
</div>
<?php
$output .= '<a href="' . $link . '">
</a>';
}
}
} else {
header("location: ./");
}
print("$output");
mysqli_close($conn);
?>
</body>
</html>
//The Pagination script file
<?php
$conn = mysqli_connect("localhost","user1234","1234pw","1234db");
$q = mysqli_query($conn, "SELECT COUNT(title) FROM search_i");
// total row count
$row = mysqli_fetch_row($q);
$rows = $row[0];
// results displayed per page
$page_rows = 1;
// page number of last page
$last = ceil($rows/$page_rows);
// makes sure $last cannot be less than 1
if($last < 1) {
$last = 1;
}
// page num
$pagenum = 1;
// get pagenum from URL if it is present otherwise it is 1
if(isset($_GET['q'])) {
$pagenum = preg_replace('#[^0-9]#', '', $_GET['q']);
}
// makes sure the page number isn't below 1, or more then our $last page
if($pagenum < 1) {
$pagenum = 1;
}
else if($pagenum > $last) {
$pagenum = $last;
}
// set the rage of rows to query for the chosen $pagenum
$limit = 'LIMIT ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
$q = mysqli_query($conn, "SELECT images, title, link FROM search_i ORDER BY title DESC $limit");
// shows the user what page they are on, and the total number of pages
$textline1 = "Search_i";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
// establish $paginationCtrls variable
$paginationCtrls = '';
// if more the 1 page
if($last != 1) {
if($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<a href="'. $row["link"].'?q='.$previous.'">Previous</a> ';
// Render clickable number links
for($i = $pagenum - 4; $i < $pagenum; $i++) {
if($i > 0) {
$paginationCtrls .= '<a href="'. $row["link"].'?q='.$i.'">'.$i.'</a> ';
}
}
}
// render the target page number without a link
$paginationCtrls .= ''. $pagenum . ' ';
// render clickable number links that appear on the right
for($i = $pagenum + 1; $i < $last; $i++) {
$paginationCtrls .= '<a href="'. $row["link"].'?q='.$i.'">'.$i.'</a> ';
// allows up to 4 pages
if($i >= $pagenum + 4) {
break;
}
}
if($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' <a href="'. $row["link"].'?q='. $next .'">Next</a> ';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Paging Example</title>
<style>
div#pagination_controls {
font-size:21px;
}
div#pagination_controls > a {
color: #06F;
}
div#pagination_controls > a:visited {
color: #06F;
}
img {
height: 200px;
width: 125px;
}
.a {
margin-top: 30px;
margin-bottom: 30px;
}
body {
background-color: pink;
font-family: arial;
}
h1 {
color: white;
}
p {
color: white;
}
a {
color: red;
}
</style>
<meta title="viewport" content="width=device-width">
<meta charset="UTF-8">
</head>
<body>
<center>
<h1><?php echo $textline1; ?> </h2>
<?php
while($row = mysqli_fetch_array($q, MYSQLI_ASSOC)) {
echo "<h3>".$row["title"]."</h1>";
echo "<img src='".$row["images"]."'>";
echo "<p><a href='".$row["link"]."'>Link</a></p>";
}
// close your database connection
mysqli_close($conn);
?>
<div>
<p><?php echo $textline2; ?></p>
<div title = "pagination_controls"><?php echo $paginationCtrls; ?></div>
</div>
</center>
</body>
</html>