douyan2002 2012-01-26 04:04
浏览 8
已采纳

数据库统计

I've thought of creating a MySQL table with the following structure:

id  |   date   |   page_address   |    ip_array
1   | 12-12-12 |  /page.php       | ip1, ip2, ip3, ip4

Then for each visited page in my website, it would:

  • check for the row containing today's date and current page (if there is none, insert one).
  • check if the visitor's ip is included in the field ip_array, if it's not, then include it.

After this, I'll have a statistic of how many different visitors I've had in each page and each day.

Is it an acceptable way of doing this?

  • 写回答

1条回答 默认 最新

  • douhao6271 2012-01-26 04:09
    关注

    NO, ip_array is not a good idea, you'd better do one record for one ip.

    id  |   date   |   page_address   | ip
    1   | 12-12-12 |  /page.php       | ip1
    2   | 12-12-12 |  /page.php       | ip2
    3   | 12-12-12 |  /page.php       | ip3
    4   | 12-12-12 |  /page.php       | ip4
    

    Then you can do a simple SELECT to count the number of different visitors for each page and each day.

    SELECT COUNT(*) FROM your_table WHERE date = ? AND page_address = ?
    

    Even you can let page_address detail store in another table, and use an page_id to relate them.

    table1:

    id  |   date   |  page_id  | ip
    1   | 12-12-12 |  1        | ip1
    2   | 12-12-12 |  1        | ip2
    3   | 12-12-12 |  1        | ip3
    4   | 12-12-12 |  1        | ip4
    

    table2:

    id  | page_address 
    1   | /page.php      
    2   | /page2.php    
    

    Then you do do a SELECT like:

    SELECT COUNT(*) 
    FROM table1 
    JOIN table2 
    ON table1.page_id = table2.id 
    WHERE table1.date =? AND table2.page_address = ?
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入