好的,这是我到目前为止所拥有的;基本上它选择最流行的哈希标签并在DESC中回显它们但是当它回显它们时它会打印出来,如下所示我如何改变它;
回应的内容 这是页面上显示的内容
Array ( [#conversation] => 1 [#new] => 1 )
选择语句如何让它回显哈希标记。
<?php
$result = mysql_query("SELECT subject, count(usr_users.subject)as subjectCount FROM usr_users
GROUP BY usr_users.subject
ORDER BY subjectCount DESC
")or die(mysql_error());
$maxLines = 10;
while ($row = mysql_fetch_array($result)) {
$str1 = $row['subject'];
$a = explode(' ', $str1);
$size = sizeof($a);
for ($i = 0; $i < $size; $i++) {
$v = $a[$i];
if ($v[0] == '#') {
$hash_arr[] = $v;
}
}
if (0 == $maxLines)
break;
}
$t = array_count_values($hash_arr);
ksort($t);
print_r($t);
?>
答案 0 :(得分:0)
试试这个
<?php
$result = mysql_query("SELECT subject, count(usr_users.subject)as subjectCount FROM usr_users
GROUP BY usr_users.subject
ORDER BY subjectCount DESC
")or die(mysql_error());
$maxLines = 10;
while($row = mysql_fetch_array( $result ))
{
$str1= $row['subject'];
$a=explode(' ',$str1);
$size=sizeof($a);
for($i=0;$i<$size;$i++){
$v=$a[$i];
if($v[0]=='#'){
$hash_arr[]=$v;
}
}
if(0==$maxLines)
break;
}
$t=array_count_values($hash_arr);
ksort($t);
//print_r($t);
while (list($key, $val) = each($t)) {
if(!empty($val)){
echo $fields= $key ."count is->";
echo $valset= $val ;// if you want to comment this value then comment it .
echo "<br>";
}
}
// or
//foreach($t as $row=>$value ){echo $row."<br>";}
?>
或使用foreach of veile
foreach($t as $row=>$value ){
echo $row."<br>";
}
如果你想用一个值替换#使用
foreach($t as $row=>$value ){
echo str_replace('#','',$row) ;
echo "</br>";
}
结果:
conversation
new
答案 1 :(得分:0)