简体   繁体   中英

SQL - Order Results by Relevance

I am currently learning MySQL, and I am getting the hang of it, but I am having a few difficulties.

This is my table structure - http://i.imgur.com/XcGKKcA.jpg

This is my code -

$host = 'localhost';
$username = 'user';
$password = 'pass';
$database = 'db';

$url = $_GET['url'];
$title = $_GET['title'];
$description = $_GET['description'];

mysql_connect($host, $username, $password);
@mysql_select_db($database) or die('DB ERROR');

$query = "SELECT * FROM search";
$result = mysql_query($query);
$number = mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $number) {

$db_url = mysql_result($result, $i, "url");
$db_title = mysql_result($result, $i, "title");
$db_description = mysql_result($result, $i, "description");

echo $i.'-'.$db_url.'-'.$db_title.'-'.$db_description.'<br />';
$i++;
}

?>

Note that the $query is not complete. How do I, for example, order that by relevance to, for example $search_query ?

Thank you in advance, and please note that I just started MySQL,

for example:

Filter:

SELECT * FROM search WHERE title = 'Vlad'

SELECT * FROM search WHERE description LIKE 'Vlad%'

Order:

SELECT * FROM search ORDER BY title DESC

SELECT * FROM search ORDER BY title ASC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM