webber82 Posted November 26, 2009 Share Posted November 26, 2009 Hi, My question is very easy but i not understand, i have table with firstname, middlename and lastname, some time the firstname contain the whole name and the middle name and last name empty, some time last is empty and the other two contain name and in some time the middlename is empty and only the firstname and lastname contain the name in the table. Now my question is if i pass a variable "$name" which contain the total name then how i search through table for the required name under the describe situation. thanks Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/ Share on other sites More sharing options...
fenway Posted November 26, 2009 Share Posted November 26, 2009 Sounds like you need to clean up your database. Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/#findComment-965913 Share on other sites More sharing options...
webber82 Posted November 26, 2009 Author Share Posted November 26, 2009 I not understand why to clean up the database these entry are not fill by mistake but its often that someone have first name only and some have middle and/or last name also. Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/#findComment-966066 Share on other sites More sharing options...
MisterWebz Posted November 26, 2009 Share Posted November 26, 2009 I don't understand what you're trying to say. Do you mean something like this? <?php $result = mysql_query("SELECT * FROM members WHERE name='$name'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/#findComment-966072 Share on other sites More sharing options...
fenway Posted November 26, 2009 Share Posted November 26, 2009 Sorry, I thought you had names spanning fields, not the reverse. You can't pass the "total name" and make it work. You'll have to search each field. Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/#findComment-966155 Share on other sites More sharing options...
webber82 Posted November 26, 2009 Author Share Posted November 26, 2009 My query is like this <?php $result = mysql_query("SELECT * FROM members WHERE fname='$name' OR mname='$name' OR lname ='$name'); ?> but it not return the result in some casese $name contain the whole name and and the three fields fname, mname and lname contain the parts but in some cased the mname and/or lname are empty due to which its give the error. Thanks for the time. Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/#findComment-966169 Share on other sites More sharing options...
fenway Posted November 27, 2009 Share Posted November 27, 2009 You'll need use LIKE and %. Quote Link to comment https://forums.phpfreaks.com/topic/182973-selecting-firstname-lastname-or-both-newbe/#findComment-966471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.