Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:Filter-MYSQL数组_Php_Mysql_Browser_Operating System_Counter - Fatal编程技术网

PHP:Filter-MYSQL数组

PHP:Filter-MYSQL数组,php,mysql,browser,operating-system,counter,Php,Mysql,Browser,Operating System,Counter,我正在开发一个访问计数器,我想根据浏览器和操作系统增加一个数字 例如: Firefox Mac OS X Safari Mac OS X Firefox Mac OS X Firefox Linux 然后网站会显示 Mac OS X 1上的Safari访问 Mac OS X 2上的Firefox访问 Linux 1上的Firefox访问 有很多浏览器和操作系统的组合,那么我想使用一种算法,可以很容易地进行计算。数据从MYSQL数据库中检索。有人知道这

我正在开发一个访问计数器,我想根据浏览器和操作系统增加一个数字

例如:

Firefox     Mac OS X 

Safari      Mac OS X 

Firefox     Mac OS X

Firefox     Linux
然后网站会显示

Mac OS X 1上的Safari访问

Mac OS X 2上的Firefox访问

Linux 1上的Firefox访问

有很多浏览器和操作系统的组合,那么我想使用一种算法,可以很容易地进行计算。数据从MYSQL数据库中检索。有人知道这样做的好方法吗?

该函数将返回一个相当大的数组,其中包含它所能知道的关于用户的所有信息

SELECT browser, os, COUNT(*) as c FROM table GROUP BY browser, os;
您应该将此数组放入数据库中,可能会为获取_browser()返回的每一条信息提供一列:

  $browser = get_browser()
  print_r($browser);

  foreach ($browser as $key => $information) { // You may want to use array_walk for this, wich is harder to read in a simple example.
    $browser_clean[$key] = mysql_real_escape_string($information); //DO NOT FORGET TO SANITIZE, ppl can spoof the browserstrings and open up SQL injection holes!
  }
  //You probably want some slightly cleaner and better way to talk to the Database then boiling up some ugly SQL-string, though.
  mysql_query('INSERT INTO browserstats (parent, platform, browser, ...restofyourfields) VALUES ('. $browser_clean['parent'] .','. $browser_clean['platform'] .','. $browser_clean['browser'] .'...restofthefields)')

)

您在数据库中究竟存储了什么
Firefox Mac OS X
这就是您存储的内容吗?