Reputation: 95
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 - https://i.sstatic.net/24P9b.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,
Upvotes: 0
Views: 407
Reputation: 550
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
Upvotes: 1