我正在尝试从MySQL表(列referrer
)中检索引用URL列表。
referrer
列多次包含相同的网址,我想在其中计算并打印网址出现的次数。然后按降序打印计数。
我有以下代码,但显然在某处错误
$ref=$icdb->get_row("SELECT COUNT(referrer) AS frequency, referrer FROM url_log WHERE u = '".$dom."' GROUP BY referrer ORDER BY frequency DESC");
foreach ($ref as $details) {
echo "<td>".$details['referrer']."</td><td>".$details['frequency']."</td>";
}
我已将一些sql数据导出为数组:
$url_log = array(
array('id' => '681','url_id' => '69','options' => '','created_day' => '20140128','created' => '1390945235','deleted' => '0','u' => 'rch.metwitter','referrer' => 'http://www.domain.com/','ipaddr' => '121.223.91.20','browser' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'),
array('id' => '685','url_id' => '69','options' => '','created_day' => '20140130','created' => '1391115029','deleted' => '0','u' => 'rch.metwitter','referrer' => 'http://www.domain.com/?page=custom&id=69','ipaddr' => '121.223.91.20','browser' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'),
array('id' => '686','url_id' => '69','options' => '','created_day' => '20140130','created' => '1391116005','deleted' => '0','u' => 'rch.metwitter','referrer' => 'http://www.domain.com/','ipaddr' => '121.223.91.20','browser' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko')
);
foreach声明给了我:
3 3 h h
答案 0 :(得分:1)
我认为你的问题是COUNT(1)。 我建议将其更改为COUNT(推荐人)。