I have two columns with stirngs ( "String1" and "String2) . How to make string inputed in text field ($search) to be comparative with sum of the both strings ("String1String2")
Something like as:

" SELECT id, string1, string2,  FROM table WHERE string1+string2 LIKE '%$search%' "

if your looking to concatinate (combine) two strings, in php, use the dot (.).

$a = "string1";
$b = "string2";
$combinedStrings = $a . $b;

But it looks to me like your trying to combine the strings in the wrong place, unless you have a column with the name of two of your other columns combined?

select * ( Concat(string1,' ',string2) as searchme )  from table where searchme like "$search"

text string single space between the columns else you get

BrownCow which wont match brown cow

select * ( Concat(string1,' ',string2) as searchme )  from table where searchme like "$search"

text string single space between the columns else you get

BrownCow which wont match brown cow

This doesn't work. It give me query error.
What is "searchme" ? Variable wich contain result from Concat, or it is new column in table?

In that case 'searchme' would be the name given to the results of the concat column. I think your missing a comma:

SELECT *, ( CONCAT(string1,' ',string2) as searchme ) FROM table WHERE searchme LIKE "$search"

In that case 'searchme' would be the name given to the results of the concat column. I think your missing a comma:

SELECT *, ( CONCAT(string1,' ',string2) as searchme ) FROM table WHERE searchme LIKE "$search"

Yes, I understand that the 'search' name is for store the result of concat. But how to define? As new variable before or as new empty column in the databese table?

Yes, I understand that the 'search' name is for store the result of concat. But how to define? As new variable before or as new empty column in the databese table?

Nothing
searchme is a calculated column, it is created and defined during the query and only exists until the query is complete, it takes the format of the colums from which it is created

I can't reslove the problem :(
Here is my code :

$query = " SELECT * (CONCAT(artist,' ',song) as searchme) FROM table WHERE searchme LIKE '$search'  " ;

artist and song are columns in my table.
I get this error :

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 '(CONCAT(artist,' ',song) as searchme) FROM tabble WHERE searchme LIKE ''' at line 1

I can't reslove the problem :(
Here is my code :

$query = " SELECT * (CONCAT(artist,' ',song) as searchme) FROM table WHERE searchme LIKE '$search'  " ;

artist and song are columns in my table.
I get this error :

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 '(CONCAT(artist,' ',song) as searchme) FROM tabble WHERE searchme LIKE ''' at line 1

anyone ??

Try this.

$query = "select * from table where Concat( column1, ' ', column2 )
LIKE '%".$search."%'";

This will return all the rows from the table where column1 concatenated with column2 matches $search.
eg.

SELECT *
FROM master_table
WHERE Concat( firstname, ' ', lastname )
LIKE '%alli gator%'

Thanks man it works :) :) :)

Thats awesome! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.