I have this simple PHP Script to fetch results from the localhost WAMP server, and when I echo the query it displays one record twice for every record I have!
Result displayed as shown in picture:
Here is the PHP MySQL script
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$movie_lists = "";
$no_result = "";
$servername = "localhost";
$username = "root";
$password = "localpass";
$dbname = "movieadventuredb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//$sql = "SELECT id, movie_quality, movie_release_date FROM movielisting";
$sql = "SELECT * FROM movielisting ORDER BY ID DESC LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo "id: " . $row["id"]. " - Name: " . $row["movie_name"]. " " . $row["movie_quality"]. "<br>";
$id = $row["id"];
$movie_quality = $row["movie_quality"];
$release_date = strftime("%Y", strtotime($row["movie_release_date"]));
$movie_lists .= "<div class='item item-1'><a href='#'><img src='inventory_images/$id.jpg'/></a>
<a href='#'><div class='overlay'>
<p class='movie_quality $movie_quality'>$movie_quality</p>
<p class='movie_year year'>$release_date</p>
</div></a>
</div>";
}
} else {
$movie_lists = "";
}
$conn->close();
?>
Below is the code for CSS for the listing.
.recent_movies_slider .recent_movie_lists {float:left; width:97%;}
.slider-horizontal {width:90%; margin:25px auto; *background:#eee; height:240px; z-index:1;}
.slider-horizontal .item {height:200px; width:150px; margin:20px 10px 0;}
.slider-horizontal .item img {height:200px; width:150px;}
.slider-vertical {width:364px; margin:25px 0; float:left; background:#eee; height:300px;}
.slider-vertical .item {height:80px; width:324px; margin:10px 0 10px 20px;}
.overlay { position: relative; top:-204px; left:0; *right:0; *bottom:0; width:150px; height:200px; z-index:2; display:block; *background:red; *background-color: rgba(0,0,0,0.5); color:#fff;}
.overlay:hover {background:rgba(48, 160, 186, 0.43) url("../default_images/play-button.png") no-repeat; background-position:50% 50%;}
.movie_quality {
position: absolute;
bottom: 5px;
left: 5px;
text-transform:uppercase;
}
.hd {background:#B43104; padding:2px; border-radius:2px;}
.cam {background:#DBA901; padding:2px; border-radius:2px;}
.year {background:#086A87; padding:2px; border-radius:2px;}
.movie_year {
position: absolute;
bottom: 5px;
right: 5px;
}
and below is the HTML to echo out the result
<div class="recent_movie_lists">
<div id="slider" class="slider-horizontal">
<?php echo $movie_lists; ?>
</div>
</div>
Try setting this: $movie_lists = (all your code); instead of $movie_lists .= (all your code).
Sorry for all the stuff above, as allready answered in the comments. Why don't you just echo out the while loop in your div?
<div class="recent_movie_lists">
<div id="slider" class="slider-horizontal">
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo "id: " . $row["id"]. " - Name: " . $row["movie_name"]. " " . $row["movie_quality"]. "<br>";
$id = $row["id"];
$movie_quality = $row["movie_quality"];
$release_date = strftime("%Y", strtotime($row["movie_release_date"]));
echo "<div class='item item-1'><a href='#'><img src='inventory_images/$id.jpg'/></a>
<a href='#'><div class='overlay'>
<p class='movie_quality $movie_quality'>$movie_quality</p>
<p class='movie_year year'>$release_date</p>
</div></a>
</div>";
}
} else {
echo "";
}
?>
</div>
</div>
As I'm assuming your keeping the HTML and PHP in the same file.
Related
I am making a blog using mysql to input and output data(blog posts) using php. I have create a table, inserted rows for the data such as: id, title, content and date in "addentry.php".
I am having problems outputting the data using php on my "viewblog.php". Where it says "//output from table"(line 115), thats where i want to output the data. Ive tried my best to find a solution.
Thanks in advance.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- image.html
A trivial document
-->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title> My Blog </title></head>
<style type ="text/css">
body{
position: fixed;
overflow:overlay;
width: 100%;
top: -20px;
left: -20px;
right: -40px;
bottom: -40px;
height: auto;
background-image:url(image.jpg);
background-size: cover;
}
.container{
background-color: #ecdad6;
padding: 30px;
width:920px;
margin-left: 25%;
padding-bottom:1000px;
padding-left:0px;
border: 2px solid black;
}
.links{
position: absolute;
padding-right: 135px;
padding-bottom: 800px;
margin-left: 680px;
margin-right: 100px;
font-size: 20px;
word-wrap: break-word;
top:-3px;
}
.blog{
position: absolute;
width:678px;
padding-bottom: 920px;
margin-left: 10px;
font-size: 20px;
text-align: left;
word-wrap: break-word;
}
ul li { margin-top: -10px; }
}
iframe{
border:2px solid black;
width:4000px;
display:block;
*}
}
</style>
<body>
<!--Logo & hyperlinked -->
<p align = "center"><img src = "Logo.jpg" alt="My logo" width="10%" height="10%"/></p>
<br/>
<hr width="50%">
<div class="container">
<div class="blog">
<?php
$host = "dbprojects.eecs.qmul.ac.uk" ;
$user = "hm315" ;
$pass = "cXtXuyf2pnF4H" ;
$db = "hm315" ;
$link = mysql_connect ( $host , $user , $pass );
if (! $link ) {
die( 'Could not connect: ' . mysql_error ());
}
echo 'Connected successfully' ;
$db_selected = mysql_select_db ( $db , $link );
if (! $db_selected ) {
die ( 'Can\'t use $db : ' . mysql_error ());
}
echo 'Connected successfully' ;
//select from table
$sql = "SELECT * FROM post02";
$row=mysql_fetch_array($sql);
echo 'selecting table works';
//output from table
//connection + database, record created and close connection.
if ($link->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $link->error;
}
mysql_close ( $link );
?>
<form action='index.php' method='get'></form>
<div class="links">
<ul><li>home</li></ul>
<ul><li>logIn</li></ul>
<ul><li>add_entry</li></ul>
</div>
</div>
</div>
</body>
</html>
<?php
$host = "xxx.ac.uk" ;
$user = "xxx" ;
$pass = "xxx" ;
$db = "xxx" ;
$link = mysql_connect ( $host , $user , $pass, $db );
if (! $link ) {
die( 'Could not connect: ' . mysql_error ());
}
echo 'Connected successfully' ;
$db_selected = mysql_select_db ( $db , $link );
if (! $db_selected ) {
die ( 'Can\'t use $db : ' . mysql_error ());
}
/*
// create a table
$sql="create table post02(id INT(6) unsigned auto_increment primary key , title varchar(30) not null, content varchar(255) not null, date TIMESTAMP)";
$connection = mysql_query($sql);
if (! $connection ) {
die ( 'Cant create table : ' . mysql_error ());
}
echo 'Created a table successfuly' ;
*/
//insert to table
echo'insert table - initializing';
if($_POST['submit']){
$title = $_POST['title'];
$content = $_POST['content'];
$date = date('l jS \of F Y h:i:s A');
}
$sql = "INSERT INTO post2('title', 'content', 'date') VALUES ($title, $content,$date))";
if($title =="" || $content=="" ){
echo "please compelete your post!";
return;
}
echo'insert table completed';
mysql_query($db ,$sql);
header("location: viewblog.php");
//record created is successful
if ($link->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $link->error;
}
mysql_close ( $link );
?>
The question was not that clear, I wrote a sample code according to the question's title. Oh, and don't forget to change your creds.
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<?php
$r = $link->query("SELECT * FROM table");
while($rf = $r->fetch_assoc())
{
echo "<tr>
<td>{$rf['column_1']}</td>
<td>{$rf['column_2']}</td>
<td>{$rf['column_2']}</td>
</tr>";
}
?>
</table>
I am trying to open a new tab with a specific url with variables on it but the variables are not passed on the second tab. please help me with this . Heres my code.
<?php
$type= $_GET['type'];
$brochure_id = $_GET['id'];
$sql1 = "SELECT * from business_type WHERE business_id = '$type'";
$q1= $conn->query($sql1);
$q1->setFetchMode (PDO::FETCH_ASSOC);
$location=" ";
while($r1 = $q1->fetch())
{
if($r1['business_type'] == "Hotel"){
$location ="hotel.php";
}
else if($r1['business_type'] == "Restaurant"){
$location ="restaurant.php";
}
else if($r1['business_type'] == "Resort"){
$location ="resort.php";
}
else if($r1['business_type'] == "Spa"){
$location ="spa.php";
}
else if($r1['business_type'] == "Entertainment"){
$location ="entertainment.php";
}
}
echo "<a href='search-result-page-" . $location . "'?id='" . $brochure_id ."'' target='_blank' style='text-decoration: none' >
<div style='width: 260px; min-height: 30px; background-color: rgba(180,180,180,0.5); position: absolute; z-index: 1000; font-size: 17px; padding: 5px; color: black'>" . $r['business_name'] . "</div>
<img src='". $r['display_pic'] ."' width='260px' height='150px' />
</a>
</td>";
if($maxcol==$column){
echo "</tr>";
$column=0;
}
}
?>
Here's what I'm basically trying to do:
Retrieve the values of a column
Store those values into an array in PHP
Echo each value with a line break in between each value
Here's my attempted code:
<?php
$connection = mysqli_connect("localhost", "root", "bruhfrogzombie098", "growtapi_social");
if (!$connection) {
die("Failed to connect to MYSQL: " . mysqli_connect_errno());
};
$members = mysqli_query($connection, "SELECT Username FROM s_users");
$members_status = mysqli_query($connection, "SELECT Status_Content FROM s_users");
$members_array = array();
while ($member = mysqli_fetch_assoc($members)) {
$members_array[] = $member;
};
$members_status_array = array();
while ($status = mysqli_fetch_assoc($members_status)) {
$members_status_array[] = $status;
};
?>
And this is where I want to echo out the values:
<center>
<h1>Members Directory</h1>
<div style="width: 20%; height; 75%; border: 3px solid black; margin: auto; overflow: hidden; overflow-y: scroll;">
<?php echo $members_array['$member'];
echo "<br />";
?>
</div>
</center>
I don't receive any errors, but the problem is that nothing shows up in the div, meaning that I either didn't retrieve the data properly or didn't use it right.
Note: I've finally moved on to writing up-to-date code, so I hope no one here comments that somewhere in this code I have outdated code ( ͡° ͜ʖ ͡°)
$members_array = array();
while ($member = mysqli_fetch_assoc($members)) {
$members_array[] = $member;
//$members_array is array and $member is array so $members_array like $members_array[][];
};
<center>
<h1>Members Directory</h1>
<div style="width: 20%; height; 75%; border: 3px solid black; margin: auto; overflow: hidden; overflow-y: scroll;">
<?
$member_count = count($members_array);
for( $i = 0 ; $i < $member_count ; $i++ ){
echo $member_array[$i]['Username'];
echo "<br />";
}
?>
</div>
</center>
So my "type1" select statement will select an issue category, and then based on that issue I want a dropdown of employees that deal with that issue in another drop down. Also how do I make all the hidden select statements occupy the same space?
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>IssueReport</title>
<script src = "../../jquery.js"></script>
<style>
body{
padding:0;
margin:0;
}
#box {
padding: 5px;
color:black;
margin: 0 auto;
border-style: solid;
border-color: #0000E6;
border-width: 2px;
background-color: #58C6EB;
width: 162px;
height: 687px;
float: left;
border-radius: 10px;
}
.word{
color: #0000E6;
}
.buttons{
background-color: #CCFFFF;
border-radius: 5px;
}
</style>
<script>
function showForm(){
var issue = document.getElementById("type1").value;
if(issue == 'Program Glitch'){
document.getElementById("IT1").style.display = "block";
}
$("#type1").onchange(function{
});
}
$(document).ready(function(){
$("#sub").click(function(){
var user_issue = $("#issue").val();
var user_priority = $("#priority").val();
var user_type = $("#type1").val();
var user_author = $("#author").val();
$.post("BugReport.php",{issue:user_issue,priority:user_priority,type1:user_type,author:user_author},function(data){
$("#result").html(data);
});
});
$("#sub").click(function(){
document.getElementById('issue').value='';
$('#type1').prop('selectedIndex', 0);
$('#priority').prop('selectedIndex', 1);
});
});
</script>
</head>
<body>
<div id="box">
<h3 class = "word" style = "margin:10px 30px 30px 30px;">Issue Report</h3>
<div class = "word" style = "width: 100px; margin-left: auto; margin-right: auto">Type Of Issue:</div>
<div style = " max-width: 150px; margin-left: auto; margin-right: auto; padding: 2px">
<form action="BugReport.html" method="post">
<select onchange = "showForm()" class = "buttons" name = "type1" id = "type1" style = 'max-width: 150px;'>
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$database = "database";
$con = mysqli_connect($servername,$username,$password,$database);
if($con->connect_error){
die("Connection failed " . $con->connect_error);
}
$sql1 = "select issue_name, issue_description from Issue";
$result = mysqli_query($con,$sql1);
while ($row = mysqli_fetch_array($result)) {
$issue = $row['issue_name'];
$des = $row['issue_description'];
echo "<option value = '$issue' title = '$des'>$issue</option>";
}
?>
</select>
</form></div>
<form action="BugReport.html" method="post">
<div id = "Buyers1" style = "visibility:hidden;"><select class = "buttons" name = "author" id = "Buyers" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = '1'";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></div></form>
<div id = "Operations1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "Operations" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 2";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "IT1" style = "display:none;"><form action="BugReport.html" method="post">
<select onchange = "showForm()" class = "buttons" name = "author" id = "IT" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 3";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "CustomerService1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "CustomerService" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 4";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "HR1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "HR" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 5";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "Logistics1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "Logistics" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 6";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<form action="BugDisplayAndReply.html" method="post">
<label></label><br>
<textarea style = "max-width: 156px; background-color: #F3F9FF; border-color: #0000E6;" cols="20" rows="34" name="issue" id = "issue" placeholder = "Enter Your Issue Here" "></textarea></form><br>
<div class = "word" style = "width: 50px; margin-left: auto; margin-right: auto">Priority:</div>
<div style = "width: 70px; margin-left: auto; margin-right: auto; padding: 2px">
<form action="BugReport.html" method="post">
<select class = "buttons" name = "priority" id = "priority">
<option value = "Low">Low</option>
<option value = "Regular" selected>Regular</option>
<option value = "High">High</option>
<option value = "Urgent">Urgent</option>
</select>
</form></div>
<div style = "width: 50px; margin-left: auto; margin-right: auto; padding: 2px">
<input class = "buttons" type ="submit" name = "sub" value = "Submit" id = "sub"></div>
<div id="result"></div>
</div>
</body>
</html>
Why always do the first result of my search term will not come out?
I noticed that it will only appear when I navigate to the page number 0.
How can I solve this?
I hope that when I navigate to page number 1, the first result will come out too!
PHP Code:
<?php
//php code goes here
include 'connect.php'; // for database connection
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
$query = $_GET['q']; // query
$button = $_GET ['submit'];
if (isset($_GET['page'])) {
$page_number = (int)$_GET['page'];
$page_number = mysqli_real_escape_string($page_number);
} else {
$page_number = 1;
}
$results_per_page = 10;
?>
HTML Code:
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#title a {
font-size: 17pt;
margin: 5px;
padding: 2px;
border-color: black;
text-decoration: underline;
width: 544px;
}
#search-result {
display: block;
border: 1px solid grey;
border-color: grey;
}
#search-result:hover {
background-color: #dddddd;
width: 544px;
}
#link {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#description {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#search-page-number {
display: block;
width: auto;
height: auto;
border: 1px solid gray;
margin: 2px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 2px;
padding-top: 2px;
list-style: none;
float: left;
text-align: center;
}
#search-page-number:hover {
background-color: #dddddd;
}
#suggestion {
border: 1px solid black;
visibility: hidden;
position: absolute;
background-color: white;
z-index: 10;
}
#suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 548px;
height: auto;
text-align: left;
padding: 2px;
}
#suggestion a:hover {
background-color: #dddddd;
width: 544px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php">
<table>
<tr>
<td>
<h2>
Brandon's Search Engine
</h2>
</td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" style="height: 27px; width: 550px; padding: 2px" name="q"
onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="closeBox()" placeholder="Search Now"/>
<input type="submit" value="Search" style="height: auto; width: 60px; padding: 2px" />
<div id="suggestion" style="width: 548px">
</div>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<?php
//count
$count_sql = "SELECT count(*) as c FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' ";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];
//SQL query
$page_number = (int)$_GET['page'];
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT " . $page_number . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
//$number_of_result = mysqli_num_rows($result);
if ($number_of_result < 1) {
echo "<b>No results found!</b>";
echo "<p>";
echo "Your search - <b>$query</b>" . " - did not match any documents. Please try different keywords.";
}
elseif ($number_of_result > 1) {
echo "<b>$number_of_result results found!</b>";
echo "<p>";
//results found here and display them
while (($row = \mysqli_fetch_array($result))) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
//echo "<p>";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
}
}
elseif ($number_of_result == 1) {
echo "<b>$number_of_result result found!</b>";
echo "<p>";
//results found here and display them
while (($row = \mysqli_fetch_array($result))) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
echo "<br />";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
}
}
?>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="page" value="<?php echo 1; ?>" />
<div id="page-number">
<?php
$max_page_number = ceil($number_of_result / $results_per_page);
if ($number_of_result == 0) {
echo " ";
}
elseif ($number_of_result != 0) {
echo "You are on page $page_number of $max_page_number.";
}
//ie if 35 results are therer then we require 4 pages that are 0 to max_page_number
//current page number is equal to page_number
//echo $max_page_number;
echo "<ul>";
//both the condition are not the neccesary
if ($max_page_number >= 1) { // if more than 2 pages
if ($page_number != 1) { //First
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=1>First</a>";
echo "</li>";
}
if ($page_number != 1) { //Previous
echo "<li id='search-page-number'>";
$prev = $page_number - 1;
echo "Previous";
echo "</li>";
}
for($index = 1 ; $index <= $max_page_number ; $index++) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=".($index).">";
echo ($index) . "</a>";
echo "</li>";
}
if ($page_number != $max_page_number) { //Next
echo "<li id='search-page-number'>";
$next = $page_number + 1;
echo "Next";
echo "</li>";
}
if ($page_number != $max_page_number) { //Last
echo "<li id='search-page-number'>";
echo "Last";
echo "</li>";
}
} elseif (($max_page_number == 1 ) ) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=1>1</a>";
echo "</li>";
}
echo "</ul>";
?>
</div>
</td>
</tr>
<tr>
<td align="center">
To insert your site in result fill in the form at here.
</td>
</tr>
</table>
</form>
</body>
</html>
Your query ends with:
"LIMIT " . $page_number . ", $results_per_page"
But that's not how the LIMIT clause works in SQL. It's defined to be:
LIMIT offset, row_count
offset is a row number, starting from 0. So if you do:
LIMIT 1, 10
You'll get records 2 through 11, not 1 through 10. The correct way to do it is:
"LIMIT " . ($page_number-1)*$results_per_page . ", $results_per_page"
Something else you should find useful is the SQL_CALC_FOUND_ROWS option to the SELECT statement. This tells MySQL to calculate how many total rows matched the criteria, even though you used LIMIT to return just a subset. This way you don't have to do two queries, one with COUNT(*) and another to get a page of data. After doing a query with this option, you can use SELECT FOUND_ROWS() to get the full count.
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT SQL_CALC_FOUND_ROWS *
FROM searchengine
WHERE title LIKE '%" . $safequery . "%'
OR keywords LIKE '%" . $safequery . "%'
OR link LIKE '%" . $safequery . "%'
LIMIT " . ($page_number-1)*results_per_page . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$count_sql = "SELECT FOUND_ROWS() AS c";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];