0

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%' "

Edited by ultras: n/a

5
Contributors
11
Replies
12
Views
8 Years
Discussion Span
Last Post by nav33n
0

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?

0
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

Edited by almostbob: n/a

0
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?

Edited by ultras1: n/a

0

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"
0

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?

0

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

0

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
0

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 ??

-1

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%'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.