Jump to content

Searching a name from full name


Nuv

Recommended Posts

I have a database something like mentioned below. Please note that this is not the complete table structure. Only the relevant is shown.

 

CREATE TABLE IF NOT EXISTS `student` (
 `id` int(13) NOT NULL AUTO_INCREMENT,
 `title` varchar(3) NOT NULL,
 `firstname` varchar(30) NOT NULL,
 `middlename` varchar(30) NOT NULL,
 `lastname` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

 

 

I'm collecting the name in 3 parts, Firstname , Middlename and Lastname . Now while searching for a name i'm trying to CONCAT all the 3 parts and then search.

 

$sql_name = mysqli_query($con, "SELECT * FROM `student` WHERE CONCAT( firstname,' ', middlename,' ', lastname ) Like '".$search."%'  LIMIT ".$start.", ".$limit."") or die("Error: ".mysqli_error($con));;

 

 

I'm only wondering if there is a better and faster way to achieve this ?

While searching over the web i saw some people using the 'difference' between name and search string and displaying it in descending order, however they weren't using MySql .

Link to comment
Share on other sites

Searching with LIKE is terrible on any meaningful amount of data.

 

Using FULLTEXT isn't useful for anything but prose.

 

There are plenty of algorithms you can use -- but what are you trying to achieve? True full-text search, or something else?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.