MySQL Forums
Forum List  »  PHP

MySQL fulltext returns duplicate rows
Posted by: Redzwan Latif
Date: November 28, 2013 07:02AM

I wrote codes to search for a keyword from different tables. This is my code :

$stmt = $conn->prepare("SELECT DISTINCT rest.*,
MATCH(rest.resname, rest.address) AGAINST(:keyword) as a,
MATCH(cuisine.cuisine) AGAINST(:keyword) as b,
MATCH(recc.recc) AGAINST(:keyword) as c,
MATCH(emenu.menu, emenu.menudesc) AGAINST(:keyword) as d,
MATCH(facilities.fac) AGAINST(:keyword) as e,
MATCH(serv.service) AGAINST(:keyword) as f
FROM rest
INNER JOIN cuisine ON rest.resID = cuisine.resID
INNER JOIN recc ON rest.resID = recc.resID
INNER JOIN emenu ON rest.resID = emenu.resID
INNER JOIN facilities ON rest.resID = facilities.resID
INNER JOIN serv ON rest.resID = serv.resID
WHERE
(
MATCH(rest.resname, rest.address) AGAINST(:keyword)
OR MATCH(cuisine.cuisine) AGAINST(:keyword)
OR MATCH(recc.recc) AGAINST(:keyword)
OR MATCH(emenu.menu, emenu.menudesc) AGAINST(:keyword)
OR MATCH(facilities.fac) AGAINST(:keyword)
OR MATCH(serv.service) AGAINST(:keyword)
)
AND (aktif = :aktif) AND (negeri = :negeri) ORDER BY resID DESC LIMIT :rowsperpage OFFSET :offset");

$stmt->bindValue(':keyword', $_GET["keyword"], PDO::PARAM_STR);
$stmt->bindValue(':negeri', $negeri, PDO::PARAM_STR);
$stmt->bindValue(':aktif', $active, PDO::PARAM_STR);
$stmt->bindValue(':rowsperpage', (int) $rowsperpage, PDO::PARAM_INT);
$stmt->bindValue(':offset', (int) $offset, PDO::PARAM_INT);
$stmt->execute();


There were 6 tables involved in this query.

Based on my thoughts, I really thinks if there are 2 same tags in a different table, it will return 2 results.

I don't know how to fix it.

Can anyone help me with this? Thanks

Options: ReplyQuote


Subject
Written By
Posted
MySQL fulltext returns duplicate rows
November 28, 2013 07:02AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.