How do I know which column matches if I have two sentences LIKEfor two different columns, and in the end one of the two columns contains a needle.
LIKE
you can do something like:
SELECT 1 AS `match`, * FROM `table` WHERE col1 LIKE 'needle%' UNION SELECT 2 AS `match`, * FROM `table` WHERE col2 LIKE 'needle%'
and use matchto know
match
Note: this can probably be written using IF()
IF()
SELECT IF(col1 LIKE 'needle%' AND col2 LIKE 'needle%', 0, IF(col1 LIKE 'needle%', 1, 2) AS match, * FROM table WHERE col1 LIKE 'needle%' OR col2 LIKE 'needle%'
match teklls that the columns fall into:
col1
col2
You can use your PHP section to check which one matches.
if (stristr($result['col1'], $queryvar) === true) // col1 matched
Source: https://habr.com/ru/post/1788912/More articles:Can I add an interval every 4 characters in vi? - viПостроение подклассов из базового абстрактного класса - scalaI need a list of all my PHP classes and the files they are in - can I do this in the Netbeans IDE? - phpRails: Can't use the methods defined in the application helper as part of email presentation development? - ruby-on-railshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1788911/how-to-copy-a-structure-with-pointers-to-data-inside-so-to-copy-pointers-and-data-they-point-to&usg=ALkJrhj1M_JdiXKCIZZYPCDhTYAePoAqewWhy does he say that "push_back" has not been declared? - c ++Socket.SendAsync does not send an order in Mono / Linux - c #Cocos2d: help understand that setblendfunc combines sprites - objective-c* .do in racks 1.2 - javaWhy does a generic .NET type have one entry in TypeDef and another open type in TypeSpec? - genericsAll Articles