Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/09/2009, 04:38
Avatar de PacoRuiz
PacoRuiz
 
Fecha de Ingreso: abril-2009
Mensajes: 254
Antigüedad: 15 años
Puntos: 3
error de sintaxis en select count

Hola, tengo un error en un código. Me dice que es un error de sintaxis, pero la he visto y me parece correcta. No sé qué pasa:

La instrucción es esta:

Código:
$result=mysql_query("select count (*)from jerarquia where tipo ='$categoria'")or die (mysql_error());
Y el mensaje de error:

Cita:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*)from jerarquia where tipo ='8'' at line 1
Ahora voy a colocar el código entero por si el error viene de otro lado, y lo que muestra. La línea del error es la 23:

Código:
<?php
function suprimehijos($tipo,$opcion){
    if ($opcion!='opcion3'){
        if ($opcion!='opcion4'){
             mysql_query("delete from tipos where IDtipo='$tipo'");
        }
        if ($opcion=='opcion2'){
                $opcion='opcion4';
        }
        $result=mysql_query("select tipo from jerarquia where padre = '$tipo' ");
        $filas=mysql_num_rows($result);
        echo"filas=$filas<br>";
        echo "tipo=$tipo, opcion=$opcion<br>";
        if($filas>0){
            while ($fila=mysql_fetch_row($result)){
                $categoria=$fila[0];
                if($opcion=='opcion1'){
                    echo "suprimehijos $categoria,$opcion<br>";
                    suprimehijos($categoria,'opcion1');
                    mysql_query("delete from jerarquia where tipo='$categoria'");    
                }
                if($opcion=='opcion4'){
                    $result=mysql_query("select count (*)from jerarquia where tipo ='$categoria'")or die (mysql_error());
                    $filas=mysql_result($result,0);
                    if ($filas==1){
                        $opcion="opcion2";
                    }
                    mysql_query("delete from jerarquia where tipo='$categoria' AND padre='$tipo'");
                    echo"voy a llamar a suprimehijos:$categoria,$opcion<br>";
                    return;
                suprimehijos($categoria,$opcion);
                }  
                if($opcion=='opcion2'){
                    $result=mysql_query("select count (*)FROM jerarquia WHERE tipo ='$categoria'");
                    $filas=mysql_num_rows($result);
                    if ($filas>1){
                        $opcion="opcion4";
                    }
                    echo"voy a llamar a suprimehijos:$categoria,$opcion<br>";
                    suprimehijos($categoria,$opcion);
                    return;
                }
            }
            mysql_query("delete from jerarquia where padre='$tipo'");
            
        }
    }
    if($opcion=='opcion3'){
        $result=mysql_query("select padre from jerarquia where tipo = '$tipo' ");
        while ($fila=mysql_fetch_row($result)){
            $abuelo=$fila[0];
            echo"el abuelo es $abuelo";
            $resultado=mysql_query("select tipo from jerarquia where padre = '$tipo' ");
            while ($linea=mysql_fetch_row($resultado)){
                $categoria=$linea[0];
                echo"el nieto es $categoria";
                mysql_query("delete from jerarquia where tipo='$categoria'");
                mysql_query("Insert jerarquia (tipo,padre) values ('$categoria','$abuelo')");
            }
        }
    
        mysql_query("delete from jerarquia where tipo=$tipo");
        mysql_query("delete from jerarquia where padre=$tipo");
        mysql_query("delete from tipos where IDtipo=$tipo");
        
    }
}
$link=mysql_connect("localhost","root","");
mysql_select_db(dbimagenes,$link);
$tipo=$_POST['tipo'];
$opcion=$_POST['opcion'];
$opcioncat=$_POST['opcioncat'];
suprimehijos($tipo,$opcion);
/*alert
echo "
<script language='JavaScript'>
var prueba = 'La categoría ha sido suprimida corréctamente. Compruebe la nueva clasificación';
alert(prueba);
location.href = \"http://localhost/imagenes/formsuprimetipo.php\";
</script>";
                         */
?>
Y lo mostrado es:

Cita:
filas=1
tipo=7, opcion=opcion4
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*)from jerarquia where tipo ='8'' at line 1