/    Sign up×
Community /Pin to ProfileBookmark

removing items from an array – mySQL/PHP

I am using mySQL for my news tables.. some of the headlines field in my table contain the exact same content (but they are from a different source so I need to keep them in the table).

Unfortnately, I don’t want to display the articles with the same headlines.. so how do I remove rows from my query array that have the identical headlines?

[code]
$sql = “SELECT id, headline FROM newsTable WHERE headline LIKE ‘%$userChannel%’ OR body LIKE ‘%$userChannel%’ LIMIT 10”;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){

echo ‘<p><a href=”http://www.foo.com/thread.php?id=’.$row[id].'”>’.$row[headline].'</a></p>’;

}
[/code]

I tried SELECT DISTINCT in mySQL but it doesn’t work.. so there must be a PHP solution to compare the headline field for each row and not display like headlines…

I then tried $row = array_unique($row); but it doesn’t work either.. I think I am using array_unique() incorrectly:

[code]
$sql = “SELECT id, headline FROM newsTable WHERE headline LIKE ‘%$userChannel%’ OR body LIKE ‘%$userChannel%’ LIMIT 10″;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
$row = array_unique($row);
echo ‘<p><a href=”http://www.foo.com/thread.php?id=’.$row[id].'”>’.$row[headline].'</a></p>’;

}
[/code]

I want to remove duplicate headline items from the array…

can anyone help me out please?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@AnotherTechGuyDec 11.2007 — try adding

GROUP BY headline

on the end of the query

How is that?
×

Success!

Help @bobafart spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...