0

我目前正在学习 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,

4

1 回答 1

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
于 2013-03-24T08:28:50.000 回答