function readtitle()
    {
        if(!is_numeric($this->rid)){
        echo "<center>对不起!网址中的ID必须为整数!<br>".__BACK__."</center>";
        exit;
        }
        $query_pagetitle="select `rtitle` from `read` where `rid`=".$this->rid;
        $result_pagetitle=mysql_query($query_pagetitle);
        $pagetitle= mysql_fetch_array ($result_pagetitle);
    if(!$pagetitle){
        
        $pagetitle="文章不存在!出错了!";
        
    }else{
        $pagetitle=htmlspecialchars($pagetitle['rtitle']);
        $updatehit=new read($this->rid,'','','','');
        $updatehit->updatehit();
    }
        return $pagetitle;
    }

解决方案 »

  1.   

    可以告诉我一下为什么mysql_result()错误了?
      

  2.   

    还有一个问题:
    当搜索结果为空的时候(也就是不存在那个文章的时候),返回的是空的,不是那个“文章不存在!出错了!”这些提示。
    这个if语句错误了吗?$pagetitle="文章不存在!出错了!"; //====================输出 单个文章 的 页面标题 =======================
    function readtitle()
    {
    if(!is_numeric($this->rid)){
    echo "<center>对不起!网址中的ID必须为整数!<br>".__BACK__."</center>";
    exit;
    }
    $query_pagetitle="select `rtitle` from `read` where `rid`=".$this->rid;
    $result_pagetitle=mysql_query($query_pagetitle);

    if(!$result_pagetitle){
    $pagetitle="文章不存在!出错了!";
    }else{
    $pagetitle=mysql_fetch_array($result_pagetitle);
    $pagetitle=htmlspecialchars($pagetitle['rtitle']);
    $updatehit=new read($this->rid,'','','','');
    $updatehit->updatehit();
    }
    return $pagetitle;
    }
      

  3.   

            $query_pagetitle="select `rtitle` from `read` where `rid`=".$this->rid;
            $result_pagetitle=mysql_query($query_pagetitle);
        if($result_pagetitle==false){
    //如果程序进入这个分支,表示的是sql语句有错,而不是文章不存在!
    //        
            $pagetitle="文章不存在!出错了!";
            
        }else{        $pagetitle=mysql_result($result_pagetitle,0,"rtitle");//这个是第137行
    //137行报错的意思是mysql_result想去读结果集某一行的记录,但那一行不存在
    //这种情况下mysql_result会报错,而且还是warning级的错误,一般不建议使用mysql_result
            $pagetitle=htmlspecialchars($pagetitle);
            $updatehit=new read($this->rid,'','','','');
            $updatehit->updatehit();
        }
      

  4.   

    实际上总共三种情况        $query_pagetitle="select `rtitle` from `read` where `rid`=".$this->rid;
            $result_pagetitle=mysql_query($query_pagetitle);
            if($result_pagetitle){
              $pagetitle='数据库语句出错了!';
           }elseif($array=mysql_fetch_array($query)){
              $pagetitle=$array['rtitle'];
           }else{
              $pagetitle='文章不存在!';
           }
      

  5.   

            if(!$result_pagetitle) //刚才少了!
      

  6.   

    你可以到DODIPHP俱乐部提问啊,那里有技术专家保证在一个工作日解答,网址是http://www.dodiphp.cn/bbs/forumdisplay.php?fid=13&;page=1
      

  7.   

    这个明显没有取出东西推荐用mysql_error()试下就知道了
      

  8.   

    在PHP手册的用户已经说得很清楚,在http://cn.php.net/manual/zh/function.mysql-result.php,的留言的第一条:mysql_result() will throw E_WARNING if mysql_query returns 0 rows. This is unlike any of the mysql_fetch_* functions so be careful of this if you have E_WARNING turned on in error_reporting(). You might want to check mysql_num_rows() before calling mysql_result()当mysql_query返回0条记录时,就会产生E_WARNING级的错误,注意在mysql_result前用mysql_num_rows() 检查,推荐使用mysql_fetch_xxxx什么的函数
      

  9.   


    但是如果那个结果中的那个$array是有很多列组成,那么该怎末做才可以使得每个都成功输出mysql_fetch_array,但是又可以提示是否获取成功呢?因为使用上面这个的时候,如果$array中有很多,要全部输出,但是用了这个的话,只会输出一个结果:
     $query_pagetitle="select `rtitle` from `read` where `rid`=".$this->rid;
            $result_pagetitle=mysql_query($query_pagetitle);
            if($result_pagetitle){
              $pagetitle='数据库语句出错了!';
           }elseif($array=mysql_fetch_array($query)){
     //       $pagetitle=$array['rtitle'];
              while($info=mysql_fetch_array($array)){
                //只会输出一个
                  //如何才可以全部输出,在可以检测是否获取成功的情况下!?       }
           }else{
              $pagetitle='文章不存在!';
           }
      

  10.   

    一个一个的话,就用while循环,就像楼主引用的那个,如果要全部输出,就不用循环,直接赋值,就是$array=mysql_fetch_array($query);这样单独一句话就行了,这个数组就是全部结果,你试一下print_r看一下,呵呵,还有那个mysql_result,PHP官方都不推荐用了,最好就别用了