Link to home
Create AccountLog in
Avatar of m_mlynek
m_mlynekFlag for Denmark

asked on

php+mysql+concat

Im having a problem with a search function. What i want is to put multiple datafields from a table into a variable wich i, in the sql can search for with LIKE '%search_str%'

So far i have:

SELECT CONCAT(firstname, ' ', lastname) as full_name FROM tablename WHERE full_name LIKE '%search_str%'

It seams like i cant search for the concated field full_name. Any way to do this? Or is there another way to collect different datafields int one variable 'fictiv field' i can search for? This is the simplyfied sql to show what i mean, i have many other records taken out with the same criterias.
Avatar of Ali Kayahan
Ali Kayahan
Flag of Türkiye image


//DB connections
$search_str = "somename or lastname" ;
$query ="SELECT concat(firstname,lastname) as m FROM user WHERE firstname LIKE '%$search_str%'" ;
$result = mysql_query($query) ;
while($row = mysql_fetch_object($result)) {
echo $row->m ;
}
ASKER CERTIFIED SOLUTION
Avatar of Ali Kayahan
Ali Kayahan
Flag of Türkiye image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer