dqve65954 2014-12-07 10:16
浏览 23

SQL页面视图Php

So i want to have page view on my php pages and googled this... i dont want to make a new database for it so ive found a available spot in my database (so cant use any solutions that requires more than 1 cell in the database.

I got this code wich counts the visit so that part works fine, but i cant seem to make the number of views to be shown (printed i guess its the right word)

<?php  //Adds one to the counter 
  mysql_query("UPDATE news SET post = post + 1, published=published, last_edit=last_edit WHERE id=$id");

//Retreives the current count 
$count1 = mysql_fetch_row(mysql_query("SELECT post FROM post"));  

// Displays the count on your site print

             echo $count1; ?>

Any idea why i wont get the result to show?

  • 写回答

3条回答 默认 最新

  • doujuan2688 2014-12-07 10:39
    关注

    $count is an array, not a scalar. Try echo $count[];

    There is a set of techniques called debugging when things don't work as expected. The very first step you make is "divide and conquer" by separating complex expressions into simple ones:

    $resource = mysql_query("SELECT count = count(post) FROM post");
    if ($resource) {
        $count = mysql_fetch_row();
        if ($count > 0) {
           echo $count[0];
        } else {
           echo 'it seems that post table is empty';
        }
    } else {
        echo 'I need to figure out what went wrong by looking in PHP documentation for mysql error query functions';
    }
    

    Secondly, when debugging, instead of echo use var_dump($resource) or var_dump($count). That way you will see the real type and value of a variables.

    PS. mysql_query is deprecated and might be removed from PHP in any future version

    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写