简体   繁体   English

PHP错误-array_multisort

[英]php error - array_multisort

Suddenly i got this error show in my index page no changes happen at all and was working for months , 突然我的索引页面上显示此错误,根本没有任何变化,并且已经工作了几个月,

PS : my live site : sudanesetweeps.com PS:我的直播网站:sudanesetweeps.com

array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in

Warning: Invalid argument supplied for foreach() in

am using the following code : 我正在使用以下代码:

<?php

require_once("dbconnect.php");
$query = " SELECT COUNT( * ) cnt, hashtags
FROM  tweets
WHERE tweeted_at > DATE_SUB( NOW( ) , INTERVAL 1 DAY ) 
AND hashtags !=  '' 
GROUP BY hashtags
ORDER BY cnt DESC ";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res) ) {
 $count = $row['cnt'];
$hashtags = explode( " ", $row['hashtags'] );
foreach($hashtags as $hashtag ) {   
 //$index = array_search($hashtag, array_keys($topics));
    if( strtolower($hashtag) != 'gmaes' && strtolower($hashtag) != 'lord'      ) 
        $topics[strtolower($hashtag)] += $count;
  }
 }

 array_multisort($topics, SORT_DESC);

 echo "<ul id='mytags'>";
 $index = 0;
  foreach($topics as $key=>$value) {
$index++;
if($key != "" ) {       
            $trending[$key] = $value;
            echo "<li><a class='size".$index."'      href='http://twitter.com/#!/search/realtime/%23".$key."'>#".$key."</a></li>";
   }
  if($index >6 ) 
  break;    
}
 echo "</ul>";

 ?>

The error is probably due to no data in your database. 该错误可能是由于数据库中没有数据。 $row['hashtags'] is empty. $row['hashtags']为空。 try executing the query directly on the sql server and see if there are any results. 尝试直接在sql服务器上执行查询,看看是否有任何结果。

Update : I updated your code to handle errors: 更新 :我更新了您的代码以处理错误:

<?php

require_once("dbconnect.php");
$query = " SELECT COUNT( * ) cnt, hashtags
FROM  tweets
WHERE tweeted_at > DATE_SUB( NOW( ) , INTERVAL 1 DAY ) 
AND hashtags !=  '' 
GROUP BY hashtags
ORDER BY cnt DESC ";
$res = mysql_query($query);
$topics = array();
while($row = mysql_fetch_assoc($res) ) {
    $count = $row['cnt'];
    $hashtags = explode( " ", $row['hashtags'] );
    if(!empty($hashtags))
    {
        foreach($hashtags as $hashtag ) {
            //$index = array_search($hashtag, array_keys($topics));
            if( strtolower($hashtag) != 'gmaes' && strtolower($hashtag) != 'lord') 
                $topics[strtolower($hashtag)] += $count;
        }
    }
}
if(!empty($topics))
{
    array_multisort($topics, SORT_DESC);

    echo "<ul id='mytags'>";
    $index = 0;
    foreach($topics as $key=>$value) {
        $index++;
        if($key != "" ) {
            $trending[$key] = $value;
            echo "<li><a class='size".$index."'      href='http://twitter.com/#!/search/realtime/%23".$key."'>#".$key."</a></li>";
        }
        if($index >6 )
            break;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM