Ver Mensaje Individual
  #17 (permalink)  
Antiguo 11/01/2011, 15:19
dasa
 
Fecha de Ingreso: marzo-2009
Mensajes: 132
Antigüedad: 15 años, 1 mes
Puntos: 8
Respuesta: Insertar multiples Registros

Gracias.
Anexo los dos codigos uno es el buscador y el otro lo que muestra. Hay otra tabla que es la de las instituciones en la cual el buscador consulta, y la tabla pedidos alli igualo por los id de las instituciones que requieren o piden algo
Buscador
Código PHP:
Ver original
  1. <?php require_once('Connections/pailinea.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }
  31.  
  32. $maxRows_BuscarIPS = 10;
  33. $pageNum_BuscarIPS = 0;
  34. if (isset($_GET['pageNum_BuscarIPS'])) {
  35.   $pageNum_BuscarIPS = $_GET['pageNum_BuscarIPS'];
  36. }
  37. $startRow_BuscarIPS = $pageNum_BuscarIPS * $maxRows_BuscarIPS;
  38.  
  39. $colname_BuscarIPS = "-1";
  40. if (isset($_POST['nombre'])) {
  41.   $colname_BuscarIPS = $_POST['nombre'];
  42. }
  43. mysql_select_db($database_pailinea, $pailinea);
  44. $query_BuscarIPS = sprintf("SELECT cod_ips, nombre FROM ips WHERE nombre LIKE %s", GetSQLValueString("%" . $colname_BuscarIPS . "%", "text"));
  45. $query_limit_BuscarIPS = sprintf("%s LIMIT %d, %d", $query_BuscarIPS, $startRow_BuscarIPS, $maxRows_BuscarIPS);
  46. $BuscarIPS = mysql_query($query_limit_BuscarIPS, $pailinea) or die(mysql_error());
  47. $row_BuscarIPS = mysql_fetch_assoc($BuscarIPS);
  48.  
  49. if (isset($_GET['totalRows_BuscarIPS'])) {
  50.   $totalRows_BuscarIPS = $_GET['totalRows_BuscarIPS'];
  51. } else {
  52.   $all_BuscarIPS = mysql_query($query_BuscarIPS);
  53.   $totalRows_BuscarIPS = mysql_num_rows($all_BuscarIPS);
  54. }
  55. $totalPages_BuscarIPS = ceil($totalRows_BuscarIPS/$maxRows_BuscarIPS)-1;
  56. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  57. <html xmlns="http://www.w3.org/1999/xhtml">
  58. <head>
  59. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  60. <title>Documento sin t&iacute;tulo</title>
  61. </head>
  62.  
  63. <body>
  64. <p>&nbsp;</p>
  65. <form id="form1" name="form1" method="post" action="">
  66.   <p>Buscar
  67.     <label>
  68.     <input type="text" name="nombre" id="nombre" />
  69.     </label>
  70.   </p>
  71.   <p>
  72.     <label>
  73.     <input type="submit" name="buscar" id="buscar" value="Enviar" />
  74.     </label>
  75. </p>
  76. </form>
  77. <?php do { ?>
  78.   <p><a href="verpedidoips.php?cod_ips=<?php echo $row_BuscarIPS['cod_ips']; ?>"><?php echo $row_BuscarIPS['nombre']; ?></a></p>
  79.   <?php } while ($row_BuscarIPS = mysql_fetch_assoc($BuscarIPS)); ?></body>
  80. </html>
  81. <?php
  82. mysql_free_result($BuscarIPS);
  83. ?>

Resultado

Código PHP:
Ver original
  1. <?php require_once('Connections/pailinea.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }
  31.  
  32. $maxRows_MostrarPedido = 10;
  33. $pageNum_MostrarPedido = 0;
  34. if (isset($_GET['pageNum_MostrarPedido'])) {
  35.   $pageNum_MostrarPedido = $_GET['pageNum_MostrarPedido'];
  36. }
  37. $startRow_MostrarPedido = $pageNum_MostrarPedido * $maxRows_MostrarPedido;
  38.  
  39. $colname_MostrarPedido = "-1";
  40. if (isset($_GET['cod_ips'])) {
  41.   $colname_MostrarPedido = $_GET['cod_ips'];
  42. }
  43. mysql_select_db($database_pailinea, $pailinea);
  44. $query_MostrarPedido = sprintf("SELECT * FROM pedidos WHERE cod_ips = %s", GetSQLValueString($colname_MostrarPedido, "int"));
  45. $query_limit_MostrarPedido = sprintf("%s LIMIT %d, %d", $query_MostrarPedido, $startRow_MostrarPedido, $maxRows_MostrarPedido);
  46. $MostrarPedido = mysql_query($query_limit_MostrarPedido, $pailinea) or die(mysql_error());
  47. $row_MostrarPedido = mysql_fetch_assoc($MostrarPedido);
  48.  
  49. if (isset($_GET['totalRows_MostrarPedido'])) {
  50.   $totalRows_MostrarPedido = $_GET['totalRows_MostrarPedido'];
  51. } else {
  52.   $all_MostrarPedido = mysql_query($query_MostrarPedido);
  53.   $totalRows_MostrarPedido = mysql_num_rows($all_MostrarPedido);
  54. }
  55. $totalPages_MostrarPedido = ceil($totalRows_MostrarPedido/$maxRows_MostrarPedido)-1;
  56.  
  57. mysql_select_db($database_pailinea, $pailinea);
  58. $query_ObtenerIPS = "SELECT ips.cod_ips, ips.nombre, pedidos.cod_ips FROM ips, pedidos WHERE ips.cod_ips = pedidos.cod_ips";
  59. $ObtenerIPS = mysql_query($query_ObtenerIPS, $pailinea) or die(mysql_error());
  60. $row_ObtenerIPS = mysql_fetch_assoc($ObtenerIPS);
  61. $totalRows_ObtenerIPS = mysql_num_rows($ObtenerIPS);
  62.  
  63. $colname_Recordset1 = "-1";
  64. if (isset($_GET['cod_ips'])) {
  65.   $colname_Recordset1 = $_GET['cod_ips'];
  66. }
  67. mysql_select_db($database_pailinea, $pailinea);
  68. $query_Recordset1 = sprintf("SELECT cod_ips, nombre FROM ips WHERE cod_ips = %s", GetSQLValueString($colname_Recordset1, "int"));
  69. $Recordset1 = mysql_query($query_Recordset1, $pailinea) or die(mysql_error());
  70. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  71. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  72. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  73. <html xmlns="http://www.w3.org/1999/xhtml">
  74. <head>
  75. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  76. <title>Documento sin t&iacute;tulo</title>
  77. <script type="text/javascript" src="ExportarExcel/jquery-1.3.2.min.js"></script>
  78. <script language="javascript">
  79. $(document).ready(function() {
  80.     $(".botonExcel").click(function(event) {
  81.         $("#datos_a_enviar").val( $("<div>").append( $("#Exportar_a_Excel").eq(0).clone()).html());
  82.         $("#FormularioExportacion").submit();
  83. });
  84. });
  85. </script>
  86. <link href="estilo/styles.css" rel="stylesheet" type="text/css" />
  87. <style type="text/css">
  88. <!--
  89. .Estilo1 {color: #000000}
  90. .Estilo2 {color: #FF0000}
  91. .botonExcel {cursor:pointer;}
  92. -->
  93. </style>
  94. </head>
  95.  
  96. <body>
  97. <p>&nbsp;</p>
  98.  
  99.  
  100. <form id="form1" name="form1" method="post" action="">
  101.   <?php echo $row_Recordset1['nombre']; ?>
  102.   <table width="792" border="0" align="center" id="Exportar_a_Excel">
  103.     <tr>
  104.       <td width="143" class="text3"><div align="center"><span class="Estilo1">Fecha de Solicitud</span></div></td>
  105.       <td width="123" class="text3"><div align="center"><span class="Estilo1">Suministro</span></div></td>
  106.       <td width="135" class="text3"><div align="center"><span class="Estilo1">Presentación</span></div></td>
  107.       <td width="153" class="text3"><div align="center"><span class="Estilo1">Casa Productora</span></div></td>
  108.       <td width="116" class="text3"><div align="center"><span class="Estilo1">Cantidad</span></div></td>
  109.       <td width="96" class="text3"><div align="center"><span class="Estilo1">Despachada</span></div></td>
  110.     </tr>
  111.     <?php do { ?>
  112.       <tr class="text3">
  113.         <td class="Estilo2"><div align="center"><?php echo $row_MostrarPedido['fecha_solicitud']; ?></div></td>
  114.         <td class="Estilo2"><div align="center"><?php echo $row_MostrarPedido['suministro']; ?></div></td>
  115.         <td class="Estilo2"><div align="center"><?php echo $row_MostrarPedido['presentacion']; ?></div></td>
  116.         <td class="Estilo2"><div align="center"><?php echo $row_MostrarPedido['casa_productora']; ?></div></td>
  117.         <td class="Estilo2"><div align="center"><?php echo $row_MostrarPedido['cantidad']; ?></div></td>
  118.         <td class="Estilo2"><label>
  119.             <div align="center">
  120.               <input name="despachada" type="text" class="Estilo1" id="despachada" value="<?php echo $row_MostrarPedido['entregada']; ?>" />
  121.             </div>
  122.           </label></td>
  123.       </tr>
  124.       <?php } while ($row_MostrarPedido = mysql_fetch_assoc($MostrarPedido)); ?>
  125.       </table>
  126.   <label>
  127.   <input type="submit" name="registrar" id="registrar" value="Enviar" />
  128.   </label>
  129.   <input name="cod_ips" type="hidden" id="cod_ips" value="<?php echo $row_MostrarPedido['cod_ips']; ?>" />
  130.   <input name="cod_ips" type="hidden" id="cod_ips" value="<?php echo $row_Recordset1['cod_ips']; ?>" />
  131. </form>
  132. <p>&nbsp;</p>
  133. <p>&nbsp;</p>
  134. </body>
  135. </html>
  136. <?php
  137. mysql_free_result($MostrarPedido);
  138.  
  139. mysql_free_result($ObtenerIPS);
  140.  
  141. mysql_free_result($Recordset1);
  142. ?>

Muchas gracias por la ayuda. Si eso no es lo que me pedias, por favor disculpame.