Topic: Help.

Hi!, my code is


function info2($clave){ //En este caso la clave será la palabra a busca.
        $respuesta = new xajaxResponse();
        $respuesta->setCharacterEncoding("ISO-8859-1");
        $LL = mysql_connect('localhost','root','')or
        die("Could not connect: " . mysql_error());   
        $t_respuesta = "";
        $consulta = "SELECT * FROM cliente where giro = '$clave'";
        //$row=mysql_fetch_array( mysql_query($consulta));
        $t_respuesta .="<h2>nada de nada</h2>";
        $respuesta->assign("info","innerHTML",$t_respuesta);
        return $respuesta;
}

this works, but when uncomment the line  "    //$row=mysql_fetch_array( mysql_query($consulta));  " not works.
why will it be?

Re: Help.

try mysql_fetch_assoc and also mysql_select_db too.

your database may not be selected yet.

mysql_select_db("your database name here");
$consulta = "SELECT * FROM cliente where giro = '$clave'";
        //$row=mysql_fetch_array( mysql_query($consulta));
        $row=mysql_fetch_assoc ( mysql_query($consulta));

Re: Help.

Hi

Be carefull with die(...) if you can't connect with database you will get problems with this function you can do something like this:

function....{
$LL = mysql_connect('localhost','root','')
if($LL){
$t_respuesta = "code blablablabla";
}else{
$t_respuesta = "Error with bbdd connection";
}
$response->assign($div,"innerHTML",$t_respuesta);

How say bluejay use:

@mysql_fetch_assoc($sql);

note: @ is for not see errors in screen.
}

With this 2 function you can get row and rows. There are adapted to a class mysql if you have any doubt u can answer me

function get_registro($consulta_id=-1){
        if ($consulta_id!=-1){
            $this->consulta_id=$consulta_id;
        }
   
        if (isset($this->consulta_id)){
            $registro = @mysql_fetch_assoc($this->consulta_id);
        }else{
            $this->set_error("[191]Consulta invalida: <b>$this->consulta_id</b>. El registro no puede ser afectado.<br />");
        }
           
        return $registro;
    }
   
    function get_registros($sql){
        $consulta_id = $this->consulta($sql);
        $registros = array();
   
        while ($fila = $this->get_registro($consulta_id, $sql)){
            $registros[] = $fila;
        }
   
        $this->liberar_resultado($consulta_id);
        return $registros;
    }

GL SEE U