Solved

php+mysql+concat

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now