I get a don't get any errors or warning. My table is called products and the field is called name. I want to find the revelance between first and second column.
Why am I missing here?
<?php
mysql_connect("localhost"," "," ");
mysql_select_db(" ");
mysql_query('set names utf8');
$query = mysql_query("SELECT t1.name AS first FROM products t1");
$row = mysql_fetch_assoc($query);
if (!$query) {
die('Invalid query: '开发者_如何学运维 . mysql_error());
}
do {
$first = $row['first'];
$query2 = mysql_query("SELECT t1.name AS first,
t2.name AS second,
(MATCH (t2.name) AGAINST ('$first')) AS relevance
FROM products t1, products t2
WHERE t1.name = '$first'
ORDER BY relevance DESC");
if (!$query2) {
die('Invalid query: ' . mysql_error());
}
$most_similar = mysql_fetch_assoc($query2);
} while ($row = mysql_fetch_assoc($query));
?>
There is no t2 in your query, but in your select you have t2.name as second
.
Actually, you don't have a FROM
clause at all...
Edit:
This is a random guess at what you're trying to achieve...I don't really know, but you should be able to edit the query as needed.
$query2 = mysql_query("SELECT '$first' AS first,
t.name AS second,
(MATCH (t.name) AGAINST ('$first')) AS relevance
FROM products t
ORDER BY relevance DESC");
Maybe you should check if $query2 is not FALSE and display an error with mysql_error() otherwise. See also the example on http://www.php.net/manual/en/function.mysql-query.php.
精彩评论