Ver Mensaje Individual
  #13 (permalink)  
Antiguo 09/08/2010, 21:46
Avatar de oscarios
oscarios
 
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

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. if(!isset($_GET['field'])){
  10.  $_GET['field']='Id';
  11. }
  12.  
  13. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  14.  
  15. switch ($theType) {
  16. case "text":
  17. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  18. break;
  19. case "long":
  20. case "int":
  21. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  22. break;
  23. case "double":
  24. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  25. break;
  26. case "date":
  27. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  28. break;
  29. case "defined":
  30. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  31. break;
  32. }
  33. return $theValue;
  34. }
  35. }
  36.  
  37. mysql_select_db($database_conbanca, $conbanca);
  38. $query_Recordset1 = "SELECT * FROM inmuebles order by ".$_GET['field']." ".$_GET['order'];
  39. $Recordset1 = mysql_query($query_Recordset1, $conbanca) or die(mysql_error());
  40. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  41. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  42. ?>
  43. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  44. <html xmlns="http://www.w3.org/1999/xhtml">
  45. <head>
  46. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  47. <title>Documento sin título</title>
  48. </head>
  49.  
  50. <body>
  51. <form id="form1" name="form1" method="get" action="prueba.php">
  52. <label>
  53. <select name="field" id="field">
  54. <option>Seleccione un campo</option>
  55. <option value="fecha">fecha</option>
  56. <option value="barrio">barrio</option>
  57. <option value="direccion">direccion</option>
  58. <option value="codigo_inm">codigo_inm</option>
  59. </select>
  60. </label>
  61. <label>
  62. <select name="order" id="order">
  63. <option selected="selected">Orden</option>
  64. <option value="ASC">Ascendente</option>
  65. <option value="DESC">Descendente</option>
  66. </select>
  67. </label>
  68. <label>
  69. <input type="submit" name="button" id="button" value="ORDENAR" />
  70. </label>
  71. </form>
  72. <p>&nbsp;</p>
  73. <table width="500" border="1" cellspacing="0" cellpadding="3">
  74. <tr>
  75. <td bgcolor="#909090">FECHA</td>
  76. <td bgcolor="#909090">BARRIO</td>
  77. <td bgcolor="#909090">DIRECCION</td>
  78. <td bgcolor="#909090">CODIGO</td>
  79. </tr>
  80. <?php do { ?>
  81. <tr>
  82. <td><?php echo $row_Recordset1['fecha']; ?></td>
  83. <td><?php echo $row_Recordset1['barrio']; ?></td>
  84. <td><?php echo $row_Recordset1['direccion']; ?></td>
  85. <td><?php echo $row_Recordset1['codigo_inm']; ?></td>
  86. </tr>
  87. <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  88. </table>
  89. </body>
  90. </html>
  91. <?php
  92. mysql_free_result($Recordset1);
  93. ?>