Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php+mysql+concat

Posted on 2008-06-11
2
Medium Priority
?
1,755 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
[X]
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
  • 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 1500 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how 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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

730 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