doutu1939 2012-03-31 17:21
浏览 50
已采纳

在PHP中创建链接的点击次数

I want to make a code that counts the click on the link which is on my website and adds 1 to the LINKCOUNT row in the mysql database, but im having trouble over coding.

This is my code when I click the LINK on my website:

mysql_connect("localhost", "123", "123") or die(mysql_error());
mysql_select_db("123") or die(mysql_error());

$result = mysql_query("SELECT id, sitename FROM links WHERE siteurl = \"www\"");
$row = mysql_fetch_array($result);

mysql_query("INSERT INTO links (linkcount) VALUES  $row['linkcount']");
$count = 0;

Not sure if that is right way of doing it, any ideas what the code will be?

EDIT

I can now add 1 to the LINKCOUNT row but every link i click adds to the same row, i need each link to have seperate row and click count.

  • 写回答

2条回答 默认 最新

  • duanchandun1860 2012-03-31 17:28
    关注

    Try this query:

    UPDATE `links` SET `linkcount` = `linkcount` + 1 WHERE `siteurl` = 'www'
    

    And about your code: your query doesn't select the linkcount column, so $row['linkcount'] is always null.

    EDIT:

    If your table doesn't contain rows for every link you want to track, you should use that kind of code:

    mysql_query("UPDATE `links` SET `linkcount` = `linkcount` + 1 WHERE `siteurl` = 'SITE_URL'");
    if(mysql_affected_rows() == 0)
        mysql_query("INSERT INTO `links` (`sitename`, `siteurl`, `linkcounter`) VALUES ('SITE_NAME', 'SITE_URL', 1)");
    

    You have to insert proper SITE_NAME and SITE_URL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)