Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Say I have a MySQL table like the one below with a list of names in an organisation, and IDs for each.
id name
1 John Doe
2 Richard Smith
3 Jane Market
... ...
Given user will query for the person's first and/or last name (with the possibility of typos and nicknames used) and php should return the closest match to their query.
For example, if a user enters "ricky" (nickname for Richard), it should return the ID for Richard Smith.
For nicknames, you have to create a separate MySQL table, with lookups (Many-to-One relationship).
For typos, you will have to loop all of your names and compare them to what the user has entered using the levenshtein function, or the similar_text function. The User Contributed Notes will help.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I have this database:
John 4.2
Robert 6
Maria 3.2
What I would want is lets say I refresh a website. And in every refresh I will get a random name from that database based on the chance of showing-> that would mean that Robert would appear more times than the other people(because of his chance)
Any way to do this? I just can't think of anything.
I've create your table with columns name and weight.
The following request return on name, depending on the weight:
SELECT name FROM table ORDER BY RAND()*weight DESC LIMIT 1;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a question about ordering search results with PHP and MySQL codes. For example, I entered "Peter has a car", and there are two entries introducing "Peter" and "car" separately in my database. Since all the entries are arranged alphabetically, the entry of "car" would be shown before that of "Peter". Would it be possible to rearrange the order of search results by according to that of appearance of keywords in a sentence I search? It means "Peter" comes first, and "car" would be the next. Thanks for help.
You can use:
ORDER BY INSTR('Peter has a car', col)
This way rows containing a col value of Peter will take precedence over rows containing a col value of car, since INSTR will return a lower number for the former.
Demo here
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have land buy/sell related website. So I want to store land area units in India and their conversion in other in units in mysql table. When user from specific area see properties list on website and if he selects acre in dropdown list then he can see the every property area in the acre though the property was listed in another unit.
So How Do I do this??
A simple two table can do this .. if you like..
Table 1:Units[id,UnitName]
Table 2:ConversionUnit[conversionId,fromUnitId,toUnitId,offset]
such as
table 1: [1,Centimetre],[2,Mitre],[3,kilometre]
table 2: [1,1,2,100],[1,3,1,0.000001]
First entry in the table to for converting CM to M and second row is to convert from KM to CM.
Hope it helps..
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Sorry for grammar mistakes. I want to create a currency table for my project which will use for adding currencies of different countries. This is my currency table but I'm confuse that this will good or not for project, so should I delete or add more columns in this table? Please help me.
currency
id | symbol | description | country | date_added | date_updated
I believe you better should have two tables.
One table for currency descriptions with fields id, symbol, description, country and other table related to this for daily currency rates with fields currency_id, rate, time_updated.
The question is if you really need the date_added. I think this is a information which is not really required.
If you want to update it regulary, I would implement a column "rate", which gives you the value in comparison of Euro or US$ as example. This way people can get a better impression how much 1 Unit of the currency is worth.
Otherwise this looks to be quite okay.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have just started PHP programming and have the following scenario;
My contact list is saved in mysql database (Fname, Lname, phone) = done
Take user input as imagining it taking from a mobile keypad .i.e. 'abc' corresponds to 1, 'def corresponds to 2 etc.
Let's say user enters "738"...this would correspond to 'PET' and so will 'REU'.
What the php code is suppose to do is get the user input in the form of digits and search through the mysql database going through the last name to see if it corresponds to any of the name and finally list those contact(s). However, since 'SET' is also a valid combination of 738 BUT if it does not exist in the database, it will not get displayed.
Question: how can i take the input in digits and generate all possible combination to match against the database? I guess i will have to use arrays to store the mobile keypad mapping and somehow do the permutations stuff.
Any help will be appreciated.
I would love to hear more about the use case where this is still worth programming in 2014.
If you really wanted to do this, you COULD enumerate all the possibilities and search that way, such as:
222 = AAA, AAB, AAC, ABA, ABB, ABC, ACA, ACB, ACC, BAA, BAB, BAC, BBA, BBB, BBC, BCA, BCB, BCC, CAA, CAB, CAC, CBA, CBB, CBC, CCA, CCB, CCC
Which is 3 cubed (27) possibilities.
However if you have 7 numbers you have 3^7th, or 2187 permutations, which is going to be an ungodly OR LIKE 'AAAAAAA%' chain.
However this method is backwards. What you should do is add a mobile-keypad-name for any name you want to search with this method, and pre-populate it with the representative digits- there will only be one possibility per name.
The SQL lookup is then a straight shot:
WHERE mobile-keypad-name = "2222222";