MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 10th, 2012, 09:40 AM
jel5363 jel5363 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 40 jel5363 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 25 m 11 sec
Reputation Power: 1
Searching for full name in database when first and last names are in dif columns

So I'm sure this is fairly a simple question, I'm just not up to speed on my mysql database functions.

I have two columns in my 'jumperprofiles' table named 'first_name' and 'last_name'. I have a form that has a dropdown with options: name, personal record, college.

At the moment, I can only search for the first name of a person in my database. I just made it that way cause thats all I knew. When name is selected, the value is 'first_name' and that is the $category. The input is the $criteria. This is the mysql statement that I've been working with.
PHP Code:
 $exSql "SELECT * FROM `jumperprofiles` WHERE $category LIKE '%".$criteria."%' ORDER BY PR DESC LIMIT $first$max"

I want to be able to type the full name into the input, either backwards or forwards, (ie. "smith, John" or "John smith") and this is the mysql statement that I've started with but I'm a little lost.
PHP Code:
 $exSql "SELECT CONCAT_WS(' ', 'first_name', 'last_name') AS 'name' FROM 'jumperprofiles' WHERE name LIKE '%".$criteria."%' ORDER BY PR DESC LIMIT $first$max"
Can anyone steer me in the right direction? Thanks for the help

Reply With Quote
  #2  
Old September 10th, 2012, 10:41 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by jel5363
Can anyone steer me in the right direction?
use the programming power of your application language (php or whatever) to analyze the contents of the form fields, split them up into first and last name values, and then query the table using two field and two values
Code:
WHERE first_name LIKE '%$firstname%'
  AND last_name LIKE '%$lastname%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old September 10th, 2012, 10:48 AM
jel5363 jel5363 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 40 jel5363 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 25 m 11 sec
Reputation Power: 1
Quote:
Originally Posted by r937
use the programming power of your application language (php or whatever) to analyze the contents of the form fields, split them up into first and last name values, and then query the table using two field and two values
Code:
WHERE first_name LIKE '%$firstname%'
  AND last_name LIKE '%$lastname%'


Alright thanks for that. Setting aside my need to learn how to do that, I already have a question. How will "it" know which is which when it splits it up? I see what you're saying. You mean to take the $_POST and split that up into $first and $last, but what if the user put the last name first and the first name last? Get what I'm saying?

Reply With Quote
  #4  
Old September 10th, 2012, 11:25 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
OR (last_name LIKE '%$firstname%'
AND first_name LIKE '%$lastname%')

?

Reply With Quote
  #5  
Old September 10th, 2012, 11:40 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by jel5363
How will "it" know which is which when it splits it up?
php is ~way~ more flexible and powerful at breaking apart the contents of a single form field into two values than sql can ever hope to be

right tool for the right job, sir

Reply With Quote
  #6  
Old September 10th, 2012, 01:36 PM
jel5363 jel5363 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 40 jel5363 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 25 m 11 sec
Reputation Power: 1
so I tried what you both said, and this is what I came up with, which isn't working, but I'm sure its something simple.

PHP Code:
 $names explode (" "$criteria);
    
$firstname $names[0];
    
$lastname $names[1];
    
$exSql "SELECT * 
FROM `jumperprofiles` 
WHERE first_name LIKE '%
$firstname%' 
AND last_name LIKE '%
$lastname%' 
OR first_name LIKE '%
$lastname%' 
AND last_name LIKE '%
$firstname%' 
ORDER BY PR DESC 
LIMIT 
$first$max
When I echo out $firstname and $lastname I get the two seperate names, so I'm not sure where I went wrong.

Reply With Quote
  #7  
Old September 10th, 2012, 02:05 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by jel5363
When I echo out $firstname and $lastname I get the two seperate names, so I'm not sure where I went wrong.
please echo out the entire sql statement

i don't do php, but it seems you're not actually executing that sql statement

Reply With Quote
  #8  
Old September 10th, 2012, 02:13 PM
jel5363 jel5363 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 40 jel5363 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 25 m 11 sec
Reputation Power: 1
Quote:
Originally Posted by r937
please echo out the entire sql statement

i don't do php, but it seems you're not actually executing that sql statement
Yea sorry, I have more to it.
PHP Code:
if ($exQuery mysqli_query($dbcon$exSql)) {
         if (
$num_rows2 != 0) {
        echo 
"<b>" .$frop."</b> through <b>" .$lrop."</b> of "
        }
        echo 
"<b>" .$num_rows2."</b> Jumpers found";
        
        if (
$totPages != 0) {
            if (
$totPages != && $totPages != 0) {
                echo 
paginate_three($reload$page$tpages$adjacents);
                }
// end of if total pages doesn't equal 1 or 0
            
echo "<hr /></div></div>";
            echo 
"<div>";
            echo 
"<table id='search' style=\"table-layout: fixed; width: 671px;\">";
            echo 
"<tr> 
            <th id='jumpername'>Jumper</th> 
            <th width='6%'>Year</th> 
            <th width='10%'>Metric</th> 
            <th width='25%'>Team</th> 
            <th width='10%x'>Gender</th> 
            <th width='14%'>Level</th> 
            <th width='10%'>Nat.</th>"
;
            while (
$row mysqli_fetch_assoc($exQuery))........ you get the idea 
Do you think its the notation I'm putting the sql in? like a ' instead of a " or nothing at all instead of a ` .... Idk, because I know I have all the right parts, but I think a piece is turned around or something.

Reply With Quote
  #9  
Old September 10th, 2012, 03:04 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
please echo out the entire sql statement

also, please describe what "not working" means... error message? 0 rows returned? wrong rows returned? computer crashes?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Searching for full name in database when first and last names are in dif columns

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap