In the tutorial there is (using my column/table names):
FROM threads WHERE {$fact_where} OR {$quote_where}But I have about 8+ columns, so how do I do the OR bit? I tried WHERE, OR, OR, OR but it doesn't work so what is the correct syntax?
Thanks
Ed
FROM threads WHERE {$fact_where} OR {$quote_where}But I have about 8+ columns, so how do I do the OR bit? I tried WHERE, OR, OR, OR but it doesn't work so what is the correct syntax?
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.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.
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>"; } } ?>
Wow nice one, sorry for that.jacek wrote:implode("%' OR `idea LIKE '%", $keywords)You missed a ` after idea.
Hard to spot !
echo mysql_error();after running your query, but before the return line.
All solvedbrisk 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.