jacek wrote:You should be able to OR, OR, OR, OR, OR ye[
try adding
[syntax=php]echo mysql_error();[/syntax]
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.
[syntax=php]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;
}
?>[/syntax]
[syntax=php]<?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>";
}
}
?> [/syntax]