I have no idea where I have gone wrong and there are no errors in the script but every time I enter something in to the search engine box it always yields no results and it still gives me the array number.
Search page:
- Code: Select all
<?php
include 'searchengine/func.inc.php';
?>
<h2>Search for Channels</h2>
<form action="" method="POST">
<p>
<input type="text" name="keywords" /> <input type="submit" value ="Search" />
</p>
</form>
<?php
if (isset($_POST['keywords'])) {
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
$errors[] = 'Please enter search terms';
} else if (strlen($keywords)<3) {
$errors[] = 'Your search term must be 3 or more characters';
} else if (search_results($keywords) === false) {
$errors[] = 'Your search returned no results';
}
if (empty($errors)) {
search_results($keywords);
} else {
foreach($errors as $error) {
echo $error, '</br>';
}
}
}
?>
Search function:
- Code: Select all
<?php
include 'db.inc.php';
function search_results($keywords) {
$returned_results = array();
$where = "";
$keywords = preg_split('/[\s]+/', $keywords);
print_r($keywords);
$total_keywords = count($keywords);
foreach($keywords as $key=>$keyword) {
$where .= "`keywords` LIKE '%$keywords%'";
if ($key != ($total_keywords - 1)) {
$where .= " AND ";
}
}
$results = "SELECT `chanelname`, LEFT(`description`, 70) as `description`, `Channeltype`, `game1`, `game2`, `keywords` FROM `Userchannel` WHERE $where";
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;
if($results_num === 0) {
return false;
} else {
echo 'Something found.';
}
}
?>
Connection to db:
- Code: Select all
<?php
mysql_connect('184.173.202.130', 'theace', '**********');
mysql_select_db('theace_LetsPlays');
?>
The database name shows up as "_LetsPlays" in the drop down menu in php my admin and I'm using a table called "Userchannel"
I hope someone can help me out!

