SQL - 按相关性排序结果

时间:2013-03-24 08:23:03

标签: php mysql sql

我目前正在学习MySQL,我正在掌握它,但我遇到了一些困难。

这是我的桌面结构 - http://i.imgur.com/XcGKKcA.jpg

这是我的代码 -     

$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++;
}

?>

请注意$query未完成。 例如,我如何按相关性排序,例如$search_query

提前感谢您,请注意我刚开始使用MySQL,

1 个答案:

答案 0 :(得分:1)

例如:

过滤器:

SELECT * FROM search WHERE title = 'Vlad'

SELECT * FROM search WHERE description LIKE 'Vlad%'

订单:

SELECT * FROM search ORDER BY title DESC

SELECT * FROM search ORDER BY title ASC