문제

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