在评论中创建五个最常用单词的列表

时间:2012-02-01 03:11:44

标签: php mysql

以下代码效果很好。它返回符合条件submissionid=$submissionid的注释列表。

我想在下面的查询返回的所有评论(comment s组合)中列出五个最常出现的单词。有点像文字云。

我怎么能这样做?

$sqlStr = "SELECT comment.comment, comment.datecommented, comment.commentid, comment.points, login.username
FROM comment
LEFT JOIN login ON comment.loginid=login.loginid
WHERE submissionid=$submissionid
ORDER BY comment.points DESC 
LIMIT 100";         

$tzFrom1 = new DateTimeZone('America/New_York'); 
$tzTo1 = new DateTimeZone('America/Phoenix'); 


$result = mysql_query($sqlStr);

$arr = array(); 
echo "<table class=\"commentecho\">";
$count = 1;
while ($row = mysql_fetch_array($result)) { 
    $dt1 = new DateTime($row["datecommented"], $tzFrom1);  
    $dt1->setTimezone($tzTo1);
    echo '<tr>';

    echo '<td style="border-left:3px solid #DE2A00; background-color: #DE2A00; border-top:3px solid #DE2A00;" class="commentname2user"><a href="http://www.domain.com/directory/'.$row["username"].'">'.$row["username"].'</a></td>';
    echo '<td style="border-bottom:3px solid #DE2A00; border-top:3px solid #DE2A00; border-right:3px solid #DE2A00;" rowspan="4" class="commentname1" id="comment-' . $row["commentid"] . '">'.stripslashes($row["comment"]).'</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td style="border-left:3px solid #DE2A00; background-color: #DE2A00;" class="commentname2">'.$dt1->format('F j, Y').'</td>';
    echo '</tr>';
    echo '<tr style="border-left:3px solid #DE2A00; background-color: #DE2A00; border-bottom:0px solid #DE2A00;">';
    echo '<td style="border-left:3px solid #DE2A00;" class="commentname2"></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td style="border-left:3px solid #DE2A00; background-color: #DE2A00; border-bottom:3px solid #DE2A00;" class="commentname2user"><span class=""><a href="http://www.domain.com/directory/comments/commentpoints.php?submission='.urlencode($submission).'&submissionid='.$submissionid.'&link='.$link.'&submittor='.$submittor.'&submissiondate='.$submissiondate.'&dispurl='.$dispurl.'&subcheck='.$subcheck.'&points='.$points.'&city='.$city.'&commentpoints='.number_format($row["points"]).'&commenter='.$row["username"].'">'.number_format($row["points"]).'</a><span></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td style="border-bottom:0px solid #DE2A00; border-right:0px solid #DE2A00;" class="commentname2a"></td>';
    echo '</tr>';
    }
echo "</table>";

0 个答案:

没有答案