I am currently building a website that relies on pulling information from my localhost database through a search bar. I currently have it displaying all the information correctly, but when a search doesn't match anything in my database then it just shows nothing, how do I change this to "No results found" or something of the sort? My code is:
<?php
require_once 'connect.php';
if(isset($_GET['keywords'])){
$keywords = $db->escape_string($_GET['keywords']);
$query = $db->query("
SELECT movie, game
FROM movies
WHERE movie LIKE '%{$keywords}%'
");
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1><a href="index.php">Test</a></h1>
<div class="search">
<form action="search.php" method="get">
<input name="keywords" type="text" placeholder="Type something!" autocomplete="off" size="40">
<input type="submit" value="Search!">
</form>
</div>
<br />
<?php
if($query->num_rows){
while($r = $query->fetch_object()){
?>
<div class="movie"> <a><?php echo $r->movie; ?></a> </div><br />
<div class="result"> <a><?php echo $r->game; ?></a> </div><br />
</body>
</html>
<?php
}
}
}
Sorry for pasting literally the full page, but I don't even know where to start as I'm a PHP noob.