Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/12/2013, 13:46
Avatar de Lynxcraft
Lynxcraft
 
Fecha de Ingreso: noviembre-2007
Ubicación: yecla murcia
Mensajes: 1.346
Antigüedad: 16 años, 5 meses
Puntos: 51
Respuesta: No me lee un objeto

Primero a funcion echo imprime a vuelo y tal como lo tinenes estas imprimiendo fuera de doc, utiliza mejor array y json
Código PHP:
<?php 
    
include("/conexiones/programa_satbalma.php");
    
$i=0;    
    
$sql="SELECT *
          FROM prueba"
;
    
$res=$db->query($sql);
    
$obj = array();
    while(
$resultado=mysqli_fetch_row($res)) {
        
$art="articulo_".$i;
        
$obj[$art]=array("cod"=>$resultado[0], "nom"=>$resultado[1], "pvp"=>$resultado[2]);
        
$i++;
    }
?>
<!DOCTYPE HTML>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Documento sin título</title>
<script language="javascript">
var lista=<?=json_encode($obj);?>;
function cod(codigo) {
    var i=0;
    for(i=0;i<20;i++) {
        var art="articulo_"+i;
        if(lista[art][cod]==codigo.value) {
            document.getElementById('nom').innerHTML=lista[art][nom];
            break;
        }
    }
}
</script>
</head>
<body>
<table>
    <tr>
        <th width="100px">
            Codigo
        </th>
        <th width="100px">
            Nombre
        </th>
        <th width="100px">
            PVP
        </th>
    </tr>
    <tr>
        <td><input type="text" name="text" id="text" onkeyup="cod(this)"></td>
        <td id="nom"></td>
        <td id="pvp"></td>
    </tr>
</table>
</body>
</html>
saludos
__________________
Sobran las ideas cuando faltan ganas de trabajar en ellas
Lynxcraft