Solved

php+mysql+concat

Posted on 2008-06-11
2
1,750 Views
Last Modified: 2008-06-11
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.
0
Comment
Question by:m_mlynek
  • 2
2 Comments
 
LVL 14

Expert Comment

by:ali_kayahan
ID: 21758552

//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 ;
}
0
 
LVL 14

Accepted Solution

by:
ali_kayahan earned 500 total points
ID: 21758565
** A little fix for searching from multiple fields (just replace query with) ;
$query ="SELECT concat(firstname,lastname) as m FROM user WHERE concat(firstname,lastname) LIKE '%$search_str%'" ;
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question