试了,没用...
apache2+php5.02+mysql5.01
是不是配置的问题?

解决方案 »

  1.   

    $category->moveTo的返回值是什么?
    true or false,还是0 or 1?
      

  2.   

    if ($res != 2) 
    ->
        if ($res != "2") 
      

  3.   

    1、直接对$res赋值,以排除不可能存在的逻辑结构问题
    2、给出moveTo方法的代码
      

  4.   

    1.测试代码如下
    if ($res) 
    {
        $res = 3;
        if ($res != 2) 
            alert("移动成功", "redirect", $_SERVER['PHP_SELF']);
        else
            alert("不能将分类添加到其子分类中.", "back");
    }
    显示移动成功
    ---------------------
    2.moveTo 代码 
    function moveTo($fromAbsPath, $toAbsPath) 
    {
        //根据节点绝对路径取出catPath
        if (strpos($toAbsPath, $fromAbsPath) === false)
        {
            $fromCatPath = $this->getCatPath($fromAbsPath);
            $fromCatID = $this->getCatID($fromAbsPath);
            $sql = "UPDATE {$this->tblName} 
                    SET catPath = REPLACE(catPath, '$fromCatPath', '$toAbsPath') 
                    WHERE catID = $fromCatID OR catPath LIKE '$fromAbsPath%'";
            //echo $sql;
            return $this->db->query($sql);
        }
        else
            return 2;
    }
      

  5.   

    补充:
    节点移动成功时能显示sql语句
    但还是弹出"不能将分类添加到其子分类中",郁闷。
      

  6.   

    function moveTo($fromAbsPath, $toAbsPath) 
    {
        //根据节点绝对路径取出catPath
        if (strpos($toAbsPath, $fromAbsPath) === false)
        {
            $fromCatPath = $this->getCatPath($fromAbsPath);
            $fromCatID = $this->getCatID($fromAbsPath);
            $sql = "UPDATE {$this->tblName} 
                    SET catPath = REPLACE(catPath, '$fromCatPath', '$toAbsPath') 
                    WHERE catID = $fromCatID OR catPath LIKE '$fromAbsPath%'";
            if($this->db->query($sql))
              return 3;
        }
        return 2;
    }
    请检查db->query($sql);的返回值,通常返回的是逻辑值或被影响的记录数
    但你的db类是作为部件嵌入在类中的,所以类的方法的返回值不应该直接使用他的返回值
      

  7.   

    和c一样,php在2个值做比较时将其中一个转换为2个值中类型低级别的那个类型(和c是相反的),在这个例子中就是int和bool,php将int型变量转化为bool值,在c语言中,非0的int值都是true,反之为false。
      

  8.   

    改成这样好用了
    if($this->db->query($sql))
        return 1;
    else
        return 0;
    检查de->query($sql)的返回值为bool是1---------------------------------------------
    但你的db类是作为部件嵌入在类中的,所以类的方法的返回值不应该直接使用他的返回值
    这是为什么呢?
      

  9.   

    正如 Debian(乌鱼子) 所说
    <?php 
    $res = 2>1; //$res 为 true
    echo "\$res的值为 $res<br>";
    if($res != 2)
      echo "$res != 2";
    else
      echo "$res == 2";
    ?>
      

  10.   

    建义返回真假值试试

        //echo $sql;
            return $this->db->query($sql);
        }
        else
            return false;
    }把判断程序改为
    if ($res) 
            alert("移动成功", "redirect", $_SERVER['PHP_SELF']);   else
            alert("不能将分类添加到其子分类中.", "back");
      

  11.   

    本以为直接return query会使代码简洁,没想到弄巧成拙