Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

php+mysql+concat

Posted on 2008-06-11
2
1,749 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using in clause in query with many values 7 54
I need to create a new user to access our RDS/MySQL database 1 55
change database name 2 36
How to fix Datetime in MySQL? 4 49
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…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

838 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