PHP为什么这段代码不回应?

时间:2013-06-11 15:50:43

标签: php mysql mysqli echo

执行以下代码后,$i如果启用了$q3删除查询,则不会回显。如果我发表评论或删除$q3,那么一切都很好。

我怎样才能让它发挥作用?

$isfound = in_array("empty",$currentrooms0);
if($isfound===true){
    for($i=0; $i<count($currentrooms0);$i++){
        if($currentrooms0[$i]=="empty"){
            $q3=mysqli_query($conn0,"delete from room_attributes where _current_created_rooms='empty' order by id desc limit 1")or die(mysqli_error($conn0));    
            echo $i-1;
            break;
        }
    }

3 个答案:

答案 0 :(得分:0)

它不会回显的原因是因为SQL中存在错误,mysqli_query在这种情况下返回false。

SQL导致错误,因为您无法在直接属于ORDER BY的{​​{1}}子句中使用WHERE

如果您要删除最顶层的属性,那么您可能需要考虑使用此sql,您的代码应该可以正常工作。

DELETE

答案 1 :(得分:0)

我认为你有问题mysqli_connect请尝试做以下..

if($q3 ===TRUE){
    echo $i-1;
    break;
}else{
    echo "Connection Problem";
}

答案 2 :(得分:-1)

OP写道:

  

这是答案:

$isfound = in_array("empty",$currentrooms0); 
if($isfound===true){ 
    for($i=0; $i<count($currentrooms0);$i++){ 
        if($currentrooms0[$i]=="empty"){ 
            $q3=mysqli_query($conn0,"delete from room_attributes where _current_created_rooms='empty' order by id desc limit 1") or die(mysqli_error($conn0)); 
            if(i>$i-1) {echo 0;}else{echo $i-1;} 
            break; 
         } 
    }
相关问题