奇怪的问题 试了,没用...apache2+php5.02+mysql5.01是不是配置的问题? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $category->moveTo的返回值是什么?true or false,还是0 or 1? if ($res != 2) -> if ($res != "2") 1、直接对$res赋值,以排除不可能存在的逻辑结构问题2、给出moveTo方法的代码 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;} 补充:节点移动成功时能显示sql语句但还是弹出"不能将分类添加到其子分类中",郁闷。 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类是作为部件嵌入在类中的,所以类的方法的返回值不应该直接使用他的返回值 和c一样,php在2个值做比较时将其中一个转换为2个值中类型低级别的那个类型(和c是相反的),在这个例子中就是int和bool,php将int型变量转化为bool值,在c语言中,非0的int值都是true,反之为false。 改成这样好用了if($this->db->query($sql)) return 1;else return 0;检查de->query($sql)的返回值为bool是1---------------------------------------------但你的db类是作为部件嵌入在类中的,所以类的方法的返回值不应该直接使用他的返回值这是为什么呢? 正如 Debian(乌鱼子) 所说<?php $res = 2>1; //$res 为 trueecho "\$res的值为 $res<br>";if($res != 2) echo "$res != 2";else echo "$res == 2";?> 建义返回真假值试试 //echo $sql; return $this->db->query($sql); } else return false;}把判断程序改为if ($res) alert("移动成功", "redirect", $_SERVER['PHP_SELF']); else alert("不能将分类添加到其子分类中.", "back"); 本以为直接return query会使代码简洁,没想到弄巧成拙 诚聘PHP程序员一名! mysqli 多次查询的问题 MySQL server has gone away 请问可不可以这样传值? php 可以设置全局的函数吗? WIN2000下PHP如何使用JPG图片文件?? 如何获取记录的条数? 求救!MSSQL问题 求电子书,关于正则表达式的 请大家帮我看看代码,为什么变量不能传递? oauth2.0 获得用户信息之后的网页前台怎么判断是不是登录成功?是js轮训吗? MYSQL问题,如果同表复制记录?在线等 这个查询没有思路了
true or false,还是0 or 1?
->
if ($res != "2")
2、给出moveTo方法的代码
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;
}
节点移动成功时能显示sql语句
但还是弹出"不能将分类添加到其子分类中",郁闷。
{
//根据节点绝对路径取出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类是作为部件嵌入在类中的,所以类的方法的返回值不应该直接使用他的返回值
if($this->db->query($sql))
return 1;
else
return 0;
检查de->query($sql)的返回值为bool是1---------------------------------------------
但你的db类是作为部件嵌入在类中的,所以类的方法的返回值不应该直接使用他的返回值
这是为什么呢?
<?php
$res = 2>1; //$res 为 true
echo "\$res的值为 $res<br>";
if($res != 2)
echo "$res != 2";
else
echo "$res == 2";
?>
//echo $sql;
return $this->db->query($sql);
}
else
return false;
}把判断程序改为
if ($res)
alert("移动成功", "redirect", $_SERVER['PHP_SELF']); else
alert("不能将分类添加到其子分类中.", "back");