MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 19th, 2004, 08:44 PM
univinus univinus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 univinus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 48 sec
Reputation Power: 0
query syntax question

i've got a form where the user can check whether a name is already in the db. At the moment, my query is:

SELECT * FROM dvdcat_director WHERE director_surname LIKE '%$searchtext%' OR director_firstname LIKE '%$searchtext%'

which works perfectly if the user enters either a surname or a first name. But if the user enters the full name, no records are found. I thought that a union would be required so I tried a query like

(SELECT * FROM dvdcat_director WHERE director_surname LIKE '%$searchtext%') UNION ( SELECT * FROM dvdcat_director WHERE director_firstname LIKE '%$searchtext%')

but this got a parse error in php.

can anyone suggest a way around this?

~magda~

Reply With Quote
  #2  
Old September 20th, 2004, 02:46 AM
oyejorge oyejorge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 25 oyejorge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 13 sec
Reputation Power: 0
Here's one idea

SELECT * FROM dvdcat_director WHERE CONCAT(director_firstname, ' ',director_surname) LIKE '%$searchtext%'

Reply With Quote
  #3  
Old September 20th, 2004, 04:49 AM
univinus univinus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 univinus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 48 sec
Reputation Power: 0
it worked! many thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > query syntax question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT