Mysql: Ignoring Duplicate Columns

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
katlis
Forum Newbie
Posts: 10
Joined: Mon Nov 05, 2007 12:42 pm

Mysql: Ignoring Duplicate Columns

Post by katlis »

Here's what I'm working on:

Code: Select all

 
$keyword = "blah";
 
$query = "SELECT *, ( (1.3 * (MATCH(title) AGAINST ('$keyword' IN BOOLEAN MODE))) + (0.6 * (MATCH(url,description) AGAINST ('$keyword' IN BOOLEAN MODE))) ) AS relevance FROM pages WHERE ( MATCH(url,title,description) AGAINST ('$keyword' IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY relevance DESC";
$result = mysql_query($query) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
$url = $row['url'];
$title = $row['title'];
echo "<a href=$url>$title</a><br>";
}
 
Now, some rows in table 'pages' have the same 'title' (they have the same 'description' too, just a slightly different 'url'). I do not want to display rows that share the same 'title', just one will do. How should I go about doing this? Can I do it in the query? I should mention that it does not matter which row is chosen and which are ignored... just need one of them.

Thanks for the help.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Mysql: Ignoring Duplicate Columns

Post by infolock »

you should look into using GROUP BY then if you don't want other rows who share the same title to display.
katlis
Forum Newbie
Posts: 10
Joined: Mon Nov 05, 2007 12:42 pm

Re: Mysql: Ignoring Duplicate Columns

Post by katlis »

Thanks infolock,
Any chance you can show me where to put GROUP BY title (I assume)? Not having any luck here with the syntax.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Mysql: Ignoring Duplicate Columns

Post by infolock »

Code: Select all

 
 
query = "SELECT *, ( (1.3 * (MATCH(title) AGAINST ('$keyword' IN BOOLEAN MODE))) + (0.6 * (MATCH(url,description) AGAINST ('$keyword' IN BOOLEAN MODE))) ) AS relevance FROM pages WHERE ( MATCH(url,title,description) AGAINST ('$keyword' IN BOOLEAN MODE) ) HAVING relevance > 0 group by title ORDER BY relevance DESC";
 
 

Edit: just a question here....why are you issuing this query this way? is your table schema (no offense) that jacked up? just curious...
Post Reply