Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/03/2010, 21:21
expecimen
 
Fecha de Ingreso: octubre-2006
Ubicación: Ciudad Ojeda, Venezuela
Mensajes: 123
Antigüedad: 17 años, 6 meses
Puntos: 0
buscador entre celdas con sql y php

Un saludos a todo, necesito una ayuda estoy buscando la forma de hacer una búsqueda sql entre celdas, me explico mejor:

Tengo unos datos registrados en una BD en sql:

código: 0001
actividad: Detal de maquinas.
%: 1
MT: 9

ahora bien en un formulario tengo dos celdas una se llama CÓDIGO y la otra se llama ACTIVIDAD ECONÓMICA lo que quiero es que cuando ingrese el código en la celda CÓDIGO este haga una búsqueda en la BD y automáticamente me cargue la actividad en la otra celda.


Cita:

--
-- Estructura de tabla para la tabla `gravamen`
--

CREATE TABLE `gravamen` (
`id` int(100) unsigned NOT NULL auto_increment,
`codigo` varchar(100) default NULL,
`actividad` varchar(100) default NULL,
`porcentaje` varchar(100) default NULL,
`mt` varchar(100) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `codigo` (`codigo`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

--
-- Volcar la base de datos para la tabla `gravamen`
--

INSERT INTO `gravamen` VALUES (1, '4200403', 'DETAL DE MAQUINAS Y ACCESORIOS PARA OFICINA', '1', '8');
INSERT INTO `gravamen` VALUES (2, '4200501', 'DETAL DE ARTICULOS DE FERRETERIA, PINTURA, LACAS, BARNICES Y MADERAS', '1', '9');

Código PHP:
<?php
$conexion
=mysql_connect("localhost","root","123456") or
die(
"Problemas en la conexion");

mysql_select_db("sedemat",$conexion) or
die(
"Problemas en la selección de la base de datos");

$registros=mysql_query("select * from gravamen
where codigo='$_REQUEST[codigo]'"
,$conexion) or
die(
"Problemas en el select:".mysql_error());
if (
$reg=mysql_fetch_array($registros))
{
}
else
echo 
"Numero no Registrado";
?>
<html>

<head>
<meta http-equiv="Content-Language" content="es-ve">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>CÓDIGO</title>
</head>

<body>

<form method="POST" action="--WEBBOT-SELF--">

<table border="1" width="1113" id="table1" cellspacing="0" cellpadding="0" bordercolor="#000000" height="72">
    <tr>
        <td width="277" align="center" height="27"><b>CÓDIGO</b></td>
        <td width="277" align="center" height="27"><b>ACTIVIDAD LABORAL</b></td>
        <td width="277" align="center" height="27"><b>%</b></td>
        <td width="278" align="center" height="27"><b>MT</b></td>
    </tr>
    <tr>
        <td width="277" align="center">
        <input type="text" name="codigo" size="20"></td>
        <td width="277" align="center">
        <input type="text" name="actividad" size="20"></td>
        <td width="277" align="center">
        <input type="text" name="porcentaje" size="20"></td>
        <td width="278" align="center"><input type="text" name="mt" size="20"></td>
    </tr>
</table>

</form>
<p align="center">&nbsp;</p>

</body>

</html>

Última edición por expecimen; 18/03/2010 a las 19:45