Actualmente me esta ingresando los id del fabricante, id del producto y id del modelo, pero yo quisiera ingresar los nombres de los fabricante, los nombres los productos y los nombres de los modelos.
ejemplo de como debiera incluirme en la tabla t_agregaequipo:
Fabricante Producto Modelo Serial Ubicacion Rack Bin Fecha
DELL Laptop Vostro 12 11111 Almacen-1 A A:1:3 7/7/2013
HP Desktop Pavilion 22222 Almacen-2 B B:2:7 8/7/2013
LEXMAR Printer X234 33333 Almacen-3 C C:1:1 9/7/2013
yo le adjunto mis archivos php y la base de datos que estoy utilizando.
Archivo principal --> f_agregaequipo.php
<?php
include "conexion.php";
?>
<html>
<head><title>SISTEMA DE INVENTARIO</title>
<script type="text/javascript" language="javascript" src="js/funciones.js"></script>
</head>
<body onload="limpiar()">
<center>
<h1><font color="green">Recepcion de Equipo</font></h1>
<hr />
<form name="f_agregaequipo" method='post' action="agregaequipo.php">
<table border="10">
<tr>
</tr><tr>
<td>Fabricante:</td>
<td>
<div id="fabricante">
<select name="fabricante" onchange="from(document.f_agregaequipo.fabricante.value,'producto','combproducto.php')">
<option selected disabled> </option>
<?php
$sql="select * from t_fabricante order by fabricante asc";
$res=mysql_query($sql,$con);
while ($reg=mysql_fetch_array($res))
{
?>
<option value="<?php echo $reg["cod_fabricante"];?>"><?php echo $reg["fabricante"];?></option>
<?php
}
?>
</select>
</div>
</td>
</tr><tr>
<td>Producto:</td>
<td>
<div id="producto">
<select name="producto">
<option selected disabled> </option>
</select>
</div>
</td>
</tr><tr>
<td>Modelo:</td>
<td>
<div id="modelo">
<select name="modelo">
<option selected disabled> </option>
</select>
</div>
</td>
</tr><tr>
<td>Serial:</td>
<td>
<input type="text" name="serial" size="30" maxlength="30" />
</td>
</tr><tr>
<td>Ubication:</td>
<td>
<input type="text" name="ubicacion" size="30" maxlength="30" />
</td>
</tr><tr>
<td>Rack:</td>
<td>
<input type="text" name="rack" size="30" maxlength="30" />
</td>
</tr><tr>
<td>Bin:</td>
<td>
<input type="text" name="bin" size="30" maxlength="30" />
</td>
</tr><tr>
<td>Date:</td>
<td>
<input Disabled name="fecha" value="<?php echo date("m/d/Y H:i:s"); ?>" size="15" />
</td>
</tr><tr>
<td><input type="submit" value="Enviar"/></td>
<td><input type ="reset" value = "reetablecer"> </td>
</tr>
</table>
</form>
</center>
<br /><hr />
</body>
</html>
Archivo que realiza el combobox o select de producto --> combproducto.php
<?php
include "conexion.php";
$sql="select * from t_producto where cod_fabricante=".$_GET["id"]."";
$res=mysql_query($sql,$con);
?>
<select name="producto" onchange="from(document.f_agregaequipo.producto.value,'modelo','combmodelo.php')">
<option selected disabled> </option>
<?php
while ($reg=mysql_fetch_array($res))
{
?>
<option value="<?php echo $reg["cod_producto"];?>"><?php echo $reg["producto"];?></option>
<?php
}
?>
</select>
Archivo que realiza el select de modelos --> combmodelo.php
<?php
include "conexion.php";
$sql="select * from t_modelo where cod_producto=".$_GET["id"]."";
$res=mysql_query($sql,$con);
?>
<select name="modelo">
<option selected disabled> </option>
<?php
while ($reg=mysql_fetch_array($res))
{
?>
<option value="<?php echo $reg["cod_modelo"];?>"><?php echo $reg["modelo"];?></option>
<?php
}
?>
</select>
Archivo que Ingresa los Datos a la tablas Mysql --> agregaequipo.php
<?php
// Se establece la conexión con la fuente de datos
$conexion = mysql_connect("localhost", "root", "");
// Si no hay conexión, se emite un error y se aborta
if (!$conexion)
die ("Error en la conexión con el gestor");
mysql_select_db("inventario") or die("Error en la Base de Datos");
// La siguiente instrucción será la inserción de un dato
$insertar ="INSERT INTO t_agregaequipo VALUES ('$_POST[fabricante]','$_POST[producto]','$_POST[modelo]','$_POST[serial]','$_POST[ubicacion]','$_POST[rack]','$_POST[bin]','$_POST[fecha]')";
// Se solicita la ejecución de la nueva instrucción (Insert)
$resultado = mysql_query($insertar);
// Se cierra la conexión
mysql_close();
require('f_agregaequipo.php');
?>
Archivo en JS que captura los datos de los select y los envia a otro select ---> funciones.js
[java]function obtiene_http_request()
{
var req = false;
try
{
req = new XMLHttpRequest(); /* p.e. Firefox */
}
catch(err1)
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
/* algunas versiones IE */
}
catch(err2)
{
try
{
req = new ActiveXObject("Microsoft.XMLHTTP");
/* algunas versiones IE */
}
catch(err3)
{
req = false;
}
}
}
return req;
}
var miPeticion = obtiene_http_request();
//***************************************************************************************
function from(id,ide,url){
var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché...
var vinculo=url "?id=" id "&rand=" mi_aleatorio;
//alert(vinculo);
miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica
miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
if (miPeticion.readyState==4)
{
//alert(miPeticion.readyState);
if (miPeticion.status==200)
{
//alert(miPeticion.status);
//var http=miPeticion.responseXML;
var http=miPeticion.responseText;
document.getElementById(ide).innerHTML= http;
}
}/*else
{
document.getElementById(ide).innerHTML="<img src='ima/loading.gif' title='cargando...' />";
}*/
}
miPeticion.send(null);
}
//************************************************************************************************
function limpiar()
{
document.form.reset();
}[/java]
BASE DE DATO MySql ---> inventario.sql
-- phpMyAdmin SQL Dump
-- version 3.4.10.1deb1
-- [url=http://www.phpmyadmin.net]http://www.phpmyadmin.net[/url]
--
-- Servidor: localhost
-- Tiempo de generación: 05-07-2013 a las 20:07:14
-- Versión del servidor: 5.5.31
-- Versión de PHP: 5.3.10-1ubuntu3.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = " 00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de datos: `inventario`
--
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_agregaequipo`
--
CREATE TABLE IF NOT EXISTS `t_agregaequipo` (
`fabricante` varchar(30) NOT NULL,
`producto` varchar(30) NOT NULL,
`modelo` varchar(30) NOT NULL,
`serial` varchar(30) NOT NULL,
`ubicacion` varchar(30) NOT NULL,
`rack` varchar(2) NOT NULL,
`bin` varchar(8) NOT NULL,
`fechaingreso` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`serial`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Volcado de datos para la tabla `t_agregaequipo`
--
INSERT INTO `t_agregaequipo` (`fabricante`, `producto`, `modelo`, `serial`, `ubicacion`, `rack`, `bin`, `fechaingreso`) VALUES
('2', '6', '5', '31425526746', 'ALMACEN-1', 'A', 'A:2:1', '0000-00-00 00:00:00'),
('1', '2', '1', '545321122', 'ALMACEN-1', 'A', 'A:2:1', '0000-00-00 00:00:00'),
('1', '1', '4', '6567854322345', 'ALMACEN-2', 'B', 'B:1:1', '0000-00-00 00:00:00'),
('3', '8', '10', '9876543433', 'ALMACEN-1', 'A', 'A:2:2', '0000-00-00 00:00:00');
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_bin`
--
CREATE TABLE IF NOT EXISTS `t_bin` (
`cod_bin` int(11) NOT NULL AUTO_INCREMENT,
`bin` varchar(30) NOT NULL,
PRIMARY KEY (`cod_bin`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
--
-- Volcado de datos para la tabla `t_bin`
--
INSERT INTO `t_bin` (`cod_bin`, `bin`) VALUES
(1, 'A:1:1'),
(2, 'A:1:2'),
(3, 'A:2:1'),
(4, 'A:2:2'),
(5, 'B:1:1'),
(6, 'C:1:1'),
(7, 'D:8:2');
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_fabricante`
--
CREATE TABLE IF NOT EXISTS `t_fabricante` (
`cod_fabricante` int(11) NOT NULL AUTO_INCREMENT,
`fabricante` varchar(30) NOT NULL,
PRIMARY KEY (`cod_fabricante`),
UNIQUE KEY `fabricante` (`fabricante`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Volcado de datos para la tabla `t_fabricante`
--
INSERT INTO `t_fabricante` (`cod_fabricante`, `fabricante`) VALUES
(1, 'DELL'),
(2, 'HP'),
(3, 'LEXMARK');
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_modelo`
--
CREATE TABLE IF NOT EXISTS `t_modelo` (
`cod_modelo` int(11) NOT NULL AUTO_INCREMENT,
`modelo` varchar(30) NOT NULL,
`cod_producto` int(11) NOT NULL,
`cod_fabricante` int(11) NOT NULL,
PRIMARY KEY (`cod_modelo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
--
-- Volcado de datos para la tabla `t_modelo`
--
INSERT INTO `t_modelo` (`cod_modelo`, `modelo`, `cod_producto`, `cod_fabricante`) VALUES
(1, 'VOSTRO 260s', 2, 1),
(2, 'VOSTRO 150', 2, 1),
(3, 'Optiplex 200', 1, 1),
(4, 'Optiplex 300', 1, 1),
(5, 'dv2000', 6, 2),
(7, 'dv3000', 6, 2),
(8, 'Pavilion 4000', 5, 2),
(9, 'Pavilion 5000', 5, 2),
(10, 'Larser X2300', 8, 3),
(11, 'Larser X4500', 8, 3),
(12, 'S-55098', 9, 3),
(13, 'S-55097', 9, 3);
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_producto`
--
CREATE TABLE IF NOT EXISTS `t_producto` (
`cod_producto` int(11) NOT NULL AUTO_INCREMENT,
`producto` varchar(30) NOT NULL,
`cod_fabricante` int(11) NOT NULL,
PRIMARY KEY (`cod_producto`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
--
-- Volcado de datos para la tabla `t_producto`
--
INSERT INTO `t_producto` (`cod_producto`, `producto`, `cod_fabricante`) VALUES
(1, 'DESKTOP', 1),
(2, 'LAPTOP', 1),
(4, 'SERVER', 1),
(5, 'DESKTOP', 2),
(6, 'LAPTOP', 2),
(7, 'SERVER', 2),
(8, 'PRINTER', 3),
(9, 'SCANER', 3);
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_rack`
--
CREATE TABLE IF NOT EXISTS `t_rack` (
`cod_rack` int(11) NOT NULL AUTO_INCREMENT,
`rack` varchar(8) NOT NULL,
PRIMARY KEY (`cod_rack`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Volcado de datos para la tabla `t_rack`
--
INSERT INTO `t_rack` (`cod_rack`, `rack`) VALUES
(1, 'A'),
(2, 'B'),
(3, 'C'),
(4, 'D');
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `t_ubicacion`
--
CREATE TABLE IF NOT EXISTS `t_ubicacion` (
`cod_ubicacion` int(11) NOT NULL AUTO_INCREMENT,
`ubicacion` varchar(30) NOT NULL,
PRIMARY KEY (`cod_ubicacion`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Volcado de datos para la tabla `t_ubicacion`
--
INSERT INTO `t_ubicacion` (`cod_ubicacion`, `ubicacion`) VALUES
(1, 'ALMACEN-1'),
(2, 'ALMACEN-2');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;