In the code below the

var_dump($row);

shows NULL

$query = "SELECT * FROM maintable WHERE Category LIKE '$word'
                                                        OR Title LIKE '$word'
                                                        OR Title2 LIKE '$word'
                                                        OR Description LIKE '$word'
                                                        OR Description2 LIKE '$word'
                                                        OR Preimushestva LIKE '$word'
                                                        OR Preimspisok LIKE '$word';";

            $result = mysqli_query($link, $query)
            or die("Error: ".mysqli_error($link));

            $row = mysqli_fetch_array($result, MYSQLI_ASSOC);

            var_dump($row);

and $word = 'dolor' and I have word dolor in my table, in Description tab help me find mistake please

有帮助吗?

解决方案

You're missing your pattern matching characters. Without them LIKE is essentially the same as =.

Here's an example:

$query = "SELECT * FROM maintable WHERE Category LIKE '%$word%'
                                                    OR Title LIKE '%$word%'
                                                    OR Title2 LIKE '%$word%'
                                                    OR Description LIKE '%$word%'
                                                    OR Description2 LIKE '%$word%'
                                                    OR Preimushestva LIKE '%$word%'
                                                    OR Preimspisok LIKE '%$word%';";

其他提示

Look at this link : http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

$query = "SELECT * FROM maintable
              WHERE Category LIKE '%".$word."%'
              OR Title LIKE '%".$word."%'
              OR Title2 LIKE '%".$word."%'
              OR Description LIKE '%".$word."%'
              OR Description2 LIKE '%".$word."%'
              OR Preimushestva LIKE '%".$word."%'
              OR Preimspisok LIKE '%".$word."%';";

My best guess would be that you need to search for '%dolor%'. The expression like without any wild card characters searches for an exact match.

However, it would help if you printed out the query after the variable substitution. You can edit your question with this information if the wildcard form doesn't fix your problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top