Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/10/2010, 15:26
Avatar de oscarios
oscarios
 
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 20 años, 2 meses
Puntos: 2
Formulario de order by

hola a todos buenas tardes, acudo a ustedes en este caso, tengo una pagina en php que muestra unos registros mysql ahi todo bien, arriba puse un formulario orderby para seleccionar por que campos ordenar la consulta pero no me ha querido funcionar,,,,,les muestro el codigo a ver si me pueden dar una manito, MIL GRACIAS
Código PHP:
Ver original
  1. <?php require_once('Connections/conbanca.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $currentPage = $_SERVER["PHP_SELF"];
  35.  
  36. $maxRows_Recordset1 = 10;
  37. $pageNum_Recordset1 = 0;
  38. if (isset($_GET['pageNum_Recordset1'])) {
  39.   $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
  40. }
  41. $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
  42.  
  43. $colname_Recordset1 = "-1";
  44. if (isset($_GET['busca'])) {
  45.   $colname_Recordset1 = $_GET['busca'];
  46. }
  47. $colname2_Recordset1 = "-1";
  48. if (isset($_GET['busca2'])) {
  49.   $colname2_Recordset1 = $_GET['busca2'];
  50. }
  51. $colname3_Recordset1 = "-1";
  52. if (isset($_GET['busca3'])) {
  53.   $colname3_Recordset1 = $_GET['busca3'];
  54. }
  55. $colname4_Recordset1 = "-1";
  56. if (isset($_GET['campo'])) {
  57.   $colname4_Recordset1 = $_GET['campo'];
  58. }
  59. $colname5_Recordset1 = "-1";
  60. if (isset($_GET['orden'])) {
  61.   $colname5_Recordset1 = $_GET['orden'];
  62. }
  63. mysql_select_db($database_conbanca, $conbanca);
  64. $query_Recordset1 = sprintf("SELECT * FROM inmuebles WHERE ciudad LIKE %s AND zona LIKE %s AND tipo LIKE %s ORDER BY %s  %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"),GetSQLValueString("%" . $colname2_Recordset1 . "%", "text"),GetSQLValueString("%" . $colname3_Recordset1 . "%", "text"),GetSQLValueString($colname4_Recordset1, "text"),GetSQLValueString($colname5_Recordset1, "text"));
  65. $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
  66. $Recordset1 = mysql_query($query_limit_Recordset1, $conbanca) or die(mysql_error());
  67. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  68.  
  69. if (isset($_GET['totalRows_Recordset1'])) {
  70.   $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
  71. } else {
  72.   $all_Recordset1 = mysql_query($query_Recordset1);
  73.   $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
  74. }
  75. $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
  76.  
  77. $queryString_Recordset1 = "";
  78. if (!empty($_SERVER['QUERY_STRING'])) {
  79.   $params = explode("&", $_SERVER['QUERY_STRING']);
  80.   $newParams = array();
  81.   foreach ($params as $param) {
  82.     if (stristr($param, "pageNum_Recordset1") == false &&
  83.         stristr($param, "totalRows_Recordset1") == false) {
  84.       array_push($newParams, $param);
  85.     }
  86.   }
  87.   if (count($newParams) != 0) {
  88.     $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  89.   }
  90. }
  91. $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
  92. ?>
  93. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  94. <html xmlns="http://www.w3.org/1999/xhtml">
  95. <head>
  96. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  97. <title>Documento sin t&iacute;tulo</title>
  98. </head>
  99.  
  100. <body>
  101. <table width="90%" border="0" cellspacing="0" cellpadding="2">
  102. </table>
  103. <table width="100%" border="0" cellspacing="0" cellpadding="2">
  104.   <tr>
  105.     <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
  106.       <tr>
  107.         <td> Registros <?php echo ($startRow_Recordset1 + 1) ?> a <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> de <?php echo $totalRows_Recordset1 ?></td>
  108.         <td><form id="form1" name="form1" method="get" action="result2b.php">
  109.           <select name="campo" id="campo">
  110.             <option value="barrio">Seleccione un campo</option>
  111.             <option value="barrio">Barrio</option>
  112.             <option value="valor">Valor</option>
  113.             <option value="area">Area</option>
  114.             <option value="habitaciones">Habitaciones</option>
  115.             <option value="codigo_inm">Codigo</option>
  116.           </select>
  117.           <select name="orden" id="orden" method="get">
  118.             <option value="ASC" selected="selected">Orden</option>
  119.             <option value="ASC">Ascendente</option>
  120.             <option value="DESC">Descendente</option>
  121.           </select>
  122.           <input name="busca" type="hidden" id="busca" value="<?php echo $row_Recordset1['ciudad']; ?>" />
  123.           <input name="busca2" type="hidden" id="busca2" value="<?php echo $row_Recordset1['zona']; ?>" />
  124.           <input name="busca3" type="hidden" id="busca3" value="<?php echo $row_Recordset1['tipo']; ?>" />
  125.           <label for="button"></label>
  126.           <input type="submit" name="button" id="button" value="Enviar" />
  127.         </form></td>
  128.         <td><table border="0">
  129.           <tr>
  130.             <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  131.                 <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border="0" /></a>
  132.                 <?php } // Show if not first page ?></td>
  133.             <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  134.                 <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border="0" /></a>
  135.                 <?php } // Show if not first page ?></td>
  136.             <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  137.                 <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="Next.gif" border="0" /></a>
  138.                 <?php } // Show if not last page ?></td>
  139.             <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  140.                 <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border="0" /></a>
  141.                 <?php } // Show if not last page ?></td>
  142.             </tr>
  143.         </table></td>
  144.       </tr>
  145.     </table></td>
  146.   </tr>
  147.   <tr>
  148.     <td><?php do { ?>
  149.         <table width="100%" border="0" cellspacing="0" cellpadding="2">
  150.           <tr>
  151.             <td rowspan="3"><img src="photos/<?php echo $row_Recordset1['foto_a']; ?>" width="150" height="112" /></td>
  152.             <td align="center">Barrio</td>
  153.             <td align="center">Valor Venta</td>
  154.             <td align="center">Area</td>
  155.             <td align="center">Habit.</td>
  156.             <td align="center">Codigo</td>
  157.             <td rowspan="3">&nbsp;</td>
  158.           </tr>
  159.           <tr>
  160.             <td align="center"><?php echo $row_Recordset1['barrio']; ?></td>
  161.             <td align="center"><?php echo $row_Recordset1['valor']; ?></td>
  162.             <td align="center"><?php echo $row_Recordset1['area']; ?></td>
  163.             <td align="center"><?php echo $row_Recordset1['habitaciones']; ?></td>
  164.             <td align="center"><?php echo $row_Recordset1['codigo_inm']; ?></td>
  165.           </tr>
  166.           <tr>
  167.             <td colspan="5"><?php echo $row_Recordset1['masinfo']; ?></td>
  168.           </tr>
  169.         </table>
  170.         <br />
  171.         <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?></td>
  172.   </tr>
  173. </table>
  174. <p>&nbsp;</p>
  175. <p>&nbsp;</p>
  176. </body>
  177. </html>
  178. <?php
  179. mysql_free_result($Recordset1);
  180. ?>
__________________
oscariosdw