Mysql fulltext search with Match and Against

57 Views Asked by At

this may be a very stupid question. However im new with mysql and hadn't that much experience.

I wanted to create a fulltext search that searches throught multiple columns for a string. I found the way with Match and Against in the internet and tried it out.

thats whats i left with:

$value = $_POST['value'];

$rechnung_search = mysql_query("SELECT * FROM testTable WHERE MATCH(`name`,`food`) AGAINST ('$value')");
while($row = mysql_fetch_array($testTable_search)){
    echo $row['name'];
    echo $row['food'];
}

with this code im getting an error that is called:

Warning: mysql_fetch_array() expects parameter 1 to be resource

as far as i know this error appears if there is a wrong information in the query. Howerver I don't know what the wrong information is. All the columns exist. What did i do wrong?

Thank you for reading! Hopefully you can help me solving this.

1

There are 1 best solutions below

1
On

Something like this

SELECT * FROM table WHERE MATCH (field1, field2, field3, field4) 
                          AGAINST ('keyword' IN BOOLEAN MODE)

Please use mysqli_* instead of mysql_. Because mysql_ was removed in PHP7.

Also, you have a mistake in your code. Instead of

while($row = mysql_fetch_array($testTable_search))

it should be

while($row = mysql_fetch_array($rechnung_search))