jacek wrote:You should be able to OR, OR, OR, OR, OR ye[
try adding
echo mysql_error();
after the failed query and see if it tells you what is wrong.
I'm getting the "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given" error. I can assure you each column has the word 'green' in it which is the word I'm searching with.
function search_posts($term){
//same as explode instead of character, will take regular expression
$keywords = preg_split('#\s+#',mysql_real_escape_string($term));
if (empty($keywords)){
return array();
}
$headline_where = "`headline` LIKE '%" . implode("%' OR `headline` LIKE '%", $keywords) . "%'";
$fact_where = "`fact` LIKE '%" . implode("%' OR `fact` LIKE '%", $keywords) . "%'";
$idea_where = "`idea` LIKE '%" . implode("%' OR `idea LIKE '%", $keywords) . "%'";
$quote_where = "`quote` LIKE '%" . implode("%' OR `quote` LIKE '%", $keywords) . "%'";
$sql = "SELECT
`headline`
`fact`
`idea`
`quote`
FROM threads
WHERE {$headline_where}
OR {$fact_where}
OR {$idea_where}
OR {$quote_where}
";
$result = mysql_query($sql);
$results = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$results[] = $row;
}
return $results;
}
?>
<?php
if (empty($_GET['term']) === false){
print_r(search_posts($_GET['term']));
echo count($search_results);
if (empty($search_results)){
echo 'Your search returned no results';
}
foreach ($search_results as $results){
echo "<h3>{results['headline']}</h3>";
echo "<h3>{results['fact']}</h3>";
echo "<h3>{results['idea']}</h3>";
echo "<h3>{results['quote']}</h3>";
}
}
?>
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\budgie\Organised2\functions\functions.php on line 486
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`idea` `quote` FROM threads WHERE `headline` LIK' at line 5
I missed out the commas for each column after 'SELECT' statement, I put them in but it's still not working proper, it's returning results though. Let me have a go first.
brisk wrote:Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\budgie\Organised2\functions\functions.php on line 486
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`idea` `quote` FROM threads WHERE `headline` LIK' at line 5
I missed out the commas for each column after 'SELECT' statement, I put them in but it's still not working proper, it's returning results though. Let me have a go first.