<div id="left">
	<h1>Search Results for <?php echo $q;?></h1>
<?php
if(empty($q)) {
	echo '<center>Search entry was empty, enter a name to search.</center>';
} elseif(!ctype_digit($q)) {
	$query = yasDB_select("SELECT * FROM games WHERE title LIKE '%$q%' OR description LIKE '%$q%' ORDER BY (CASE WHEN title LIKE '%$q%' THEN 1 ELSE 0 END) DESC limit 20");
}
if($query->num_rows ==0) {
	echo "No results!";
	echo "";
}
while($games = $query->fetch_array(MYSQLI_ASSOC)) {
	$gameurl = $games['title'];
	$gameurl = str_replace(" ", "-", $gameurl);
	$gameurl = str_replace("'", "_", $gameurl);
	$gameurl = str_replace('"', "_", $gameurl);
	$gameurl = str_replace('/', "_", $gameurl);
	$gameurl = str_replace("\\", "_", $gameurl);
	$gameurl = rawurlencode($gameurl);
	$games['description'] = stripslashes($games['description']);
	if(strlen($games['description']) > 135){
		$games['description'] = substr($games['description'], 0, 135)."...";
	}
	if ($setting['seo']=='yes') {
		echo '<div class="category_box"><div class="gamepic">
		<a href="' . $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html' . '">
		<img align="absmiddle" src="' . $setting['siteurl'] . '' . $games['thumbnail'] . '" alt="' . $games['title'] . '" width="80" height="80" /></div><div class="game_text"><strong>' . $games['title'] . '</strong></a> <div> ' . $games['description'] . '</div></div>
		<div class="game_stats"><strong>Plays:</strong>' . $games['plays'] . '</div><br style="clear: both"/></div>'; 
	} else {
		echo '<div class="category_box"><div class="gamepic">
		<a href="' . $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'] . '">
		<img align="absmiddle" src="' . $setting['siteurl'] . '' . $games['thumbnail'] . '" alt="' . $games['title'] . '" width="80" height="80"" /></div><div class="game_text"><strong>' . $games['title'] . '</strong></a> <div> ' . $games['description'] . '</div></div>
		<div class="game_stats"><strong>Plays:</strong>' . $games['plays'] . '</div><br style="clear: both"/></div>';
	}
}
?>