Ordering search results [closed] - php

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

Related

SQL - Query to find records that contain part of the value [closed]

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 11 months ago.
Improve this question
I have table zipcode which has a column called code. The Code column contains the prefix of zipcodes like
395
453
302
1203
12
I want to write an SQL query that checks if the provided zipcode matches one of the values in the table. (Something like isValid)
I want to avoid writing all zip codes in the database.
Valid Input zipcode
395004
395152
3952
1256
Can anyone help me? Thanks
simple sql query:
select *
from zipcode
where '395004' LIKE CONCAT(code,'%');
references: SQL - Query to find if a string contains part of the value in Column

Display an icon for each number of bedrooms (property website) php [closed]

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 6 years ago.
Improve this question
I have a property website.
At the moment, on the listing, and in search results, it says Number of bedrooms: [pulls the number from the database]. It uses an array variable, $a1[rooms].
Instead, I want to display a small icon of a bed for the number of bedrooms. So if three bedrooms then it should say, Number of bedrooms: [bed img] [bed img] [bed img]. [bed img] of course being a small icon/image of a bed.
So whether there are 1 bedrooms or 5 bedrooms, this is the number of times I want the icon displayed. The number of bedrooms is stored here: $a1[rooms].
Fairly simple really.
Thanks in advance.
Something like this will do the trick:
for ($bed_counter = 1; $bed_counter <= $a1['rooms']; $bed_counter++) {
print '<img src="bed.jpg">';
}

how to insert multiple line textarea value in mysql table [closed]

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 8 years ago.
Improve this question
I have a textarea and I want to insert values of that textarea to a mysql table. But I want to insert each line to each field. Like the textarea has 3 lines...each line should be inserted in 3 each field in the table. Can anyone please help me with this.
Regards,
Explode the value of the textarea (see PHP manual for the syntax of explode). You will end up with a string array with 3 items. Now you can process each of these items individually.
Do you really mean columns (fields) and not rows? If someone enters 100 lines in the textarea you would neet 100 columns. This is considered to be bad data design.

Store area unit conversion in mysql table [closed]

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..

Intelligent closest match detection with names in MySQL and PHP [closed]

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.

Categories