Foros del Web » Programando para Internet » PHP »

Ordenar consulta

Estas en el tema de Ordenar consulta en el foro de PHP en Foros del Web. Hola amigos de FOROS DEL WEB, buenas noches, recurro a su ayuda profesional esta vez, puesto que tengo una pagina web en php que despliega ...
  #1 (permalink)  
Antiguo 08/08/2010, 23:12
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Ordenar consulta

Hola amigos de FOROS DEL WEB, buenas noches, recurro a su ayuda profesional esta vez, puesto que tengo una pagina web en php que despliega un listado de productos contenido en una base de datos de mysql, hasta aqui ningun problema, pero deseo que al dar click sobre el titulo de cada columna el listado se ordene asc o des. GRACIAS POR SU ATENCION! espero me puedan sacar de esta! NOTA: Casi no se de programacion trabajo con DW.
  #2 (permalink)  
Antiguo 09/08/2010, 01:19
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Ordenar consulta

hola
bueno, pues necesitas 3 cosas
0. al titulo de cada columna agregarle un href que vaya a la misma página que se esta visualizando, y que envie dos parametro llamados por ej $field y $order de este modo
http://url?field=id&order=desc (order sera ASC o DESC y field debe ser el nombre de cada columna coincidente con el mismo nombre que tiene el campo en la base de datos)
1. a la consulta agregarle un "order by $_GET['field'] $_GET['order']"
2. validar que si no se ha obtenido nada en $_GET['field'] ni en $_GET['order'] le asigne a estas valores por defecto. y en caso contrario pues que use los valores que lleguen

y con esto debe funcionarte (espero que tengas conocimientos básicos de validación)
prueba y comentas
saludos
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com
  #3 (permalink)  
Antiguo 09/08/2010, 02:42
Avatar de andrewp  
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 1.160
Antigüedad: 20 años, 8 meses
Puntos: 5
Respuesta: Ordenar consulta

Hola Oscarios...

Lo que te aconseja mortiprogramador es una buena opción. Por otro lado, hay una serie de recurso llamados 'jQuery Plugins' que te permiten hacerlo de forma 'casi automática' insertando una serie de archivos 'JSON' a tus páginas PHP.

Si clicas aquí, podrás ver un ejemplo llamado "table sorted' que se aplica a cualquier contenido listado e impreso a través de PHP. La lectura está disponible en inglés, no le he podido conseguir en castellano, pero creo que es muy clara con los ejemplos on-line.

Saludos!
__________________
Andrew :P
  #4 (permalink)  
Antiguo 09/08/2010, 07:35
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

Mil Gracias por sus respuestas, voy a probar las dos opciones y ya les contare como me fue! un abrazo y de nuevo gracias.
  #5 (permalink)  
Antiguo 09/08/2010, 09:26
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

hola amigos, bueno la primera solucion que me da mortiprogramador no me funciono y la de andrewp es una buena opcion para conseguir buenas cosas pero les cuento yo estoy buscando algo asi como esta en esta pagina
http://www.metrocuadrado.com/servlet...rInmueblesSolr
la herramienta ordenar por que es un form donde escoges el nombre del campo y en otro selec el orden asc o desc, trate con los datos que me da morti pero no me da, GRACIAS POR SU ATENCION E INTENCION DE AYUDA!!!! quedo en espera de sus comentarios.
  #6 (permalink)  
Antiguo 09/08/2010, 09:49
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

mira esta es la pagina en la que estoy tratando de hacer lo que me dices
http://www.bancaci.com/prueba.php

y este es el codigo!!!

<?php require_once('Connections/conbanca.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_conbanca, $conbanca);
$query_Recordset1 = "SELECT * FROM inmuebles order by $_GET['field'] $_GET['order']";
$Recordset1 = mysql_query($query_Recordset1, $conbanca) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<form id="form1" name="form1" method="get" action="prueba.php">
<label>
<select name="field" id="field">
<option>Seleccione un campo</option>
<option value="fecha">fecha</option>
<option value="barrio">barrio</option>
<option value="direccion">direccion</option>
<option value="codigo_inm">codigo_inm</option>
</select>
</label>
<label>
<select name="order" id="order">
<option selected="selected">Orden</option>
<option value="ASC">Ascendente</option>
<option value="DESC">Descendente</option>
</select>
</label>
<label>
<input type="submit" name="button" id="button" value="ORDENAR" />
</label>
</form>
<p>&nbsp;</p>
<table width="500" border="1" cellspacing="0" cellpadding="3">
<tr>
<td bgcolor="#909090">FECHA</td>
<td bgcolor="#909090">BARRIO</td>
<td bgcolor="#909090">DIRECCION</td>
<td bgcolor="#909090">CODIGO</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['fecha']; ?></td>
<td><?php echo $row_Recordset1['barrio']; ?></td>
<td><?php echo $row_Recordset1['direccion']; ?></td>
<td><?php echo $row_Recordset1['codigo_inm']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
  #7 (permalink)  
Antiguo 09/08/2010, 16:55
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Ordenar consulta

hola
bueno, estoy ingresando a la página y da error en la línea 35

y pues sería bueno que cuando copies código php uses el highlight para saber
el número de línea

Código PHP:
Ver original
  1. <?php
  2. echo 'probando';
  3. ?>

y tienes el script de la tabla? sería bueno también para
hacer pruebas con esos datos

saludos
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com
  #8 (permalink)  
Antiguo 09/08/2010, 19:41
Avatar de 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.  
  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. mysql_select_db($database_conbanca, $conbanca);
  35. $query_Recordset1 = "SELECT * FROM inmuebles order by $_GET['field'] $_GET['order']";
  36. $Recordset1 = mysql_query($query_Recordset1, $conbanca) or die(mysql_error());
  37. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  38. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml">
  42. <head>
  43. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  44. <title>Documento sin título</title>
  45. </head>
  46.  
  47. <body>
  48. <form id="form1" name="form1" method="get" action="prueba.php">
  49. <label>
  50. <select name="field" id="field">
  51. <option>Seleccione un campo</option>
  52. <option value="fecha">fecha</option>
  53. <option value="barrio">barrio</option>
  54. <option value="direccion">direccion</option>
  55. <option value="codigo_inm">codigo_inm</option>
  56. </select>
  57. </label>
  58. <label>
  59. <select name="order" id="order">
  60. <option selected="selected">Orden</option>
  61. <option value="ASC">Ascendente</option>
  62. <option value="DESC">Descendente</option>
  63. </select>
  64. </label>
  65. <label>
  66. <input type="submit" name="button" id="button" value="ORDENAR" />
  67. </label>
  68. </form>
  69. <p>&nbsp;</p>
  70. <table width="500" border="1" cellspacing="0" cellpadding="3">
  71. <tr>
  72. <td bgcolor="#909090">FECHA</td>
  73. <td bgcolor="#909090">BARRIO</td>
  74. <td bgcolor="#909090">DIRECCION</td>
  75. <td bgcolor="#909090">CODIGO</td>
  76. </tr>
  77. <?php do { ?>
  78. <tr>
  79. <td><?php echo $row_Recordset1['fecha']; ?></td>
  80. <td><?php echo $row_Recordset1['barrio']; ?></td>
  81. <td><?php echo $row_Recordset1['direccion']; ?></td>
  82. <td><?php echo $row_Recordset1['codigo_inm']; ?></td>
  83. </tr>
  84. <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  85. </table>
  86. </body>
  87. </html>
  88. <?php
  89. mysql_free_result($Recordset1);
  90. ?>
  #9 (permalink)  
Antiguo 09/08/2010, 19:44
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

Código MySQL:
Ver original
  1. -- phpMyAdmin SQL Dump
  2. -- version 2.10.3
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Servidor: localhost
  6. -- Tiempo de generación: 09-08-2010 a las 21:43:02
  7. -- Versión del servidor: 5.0.51
  8. -- Versión de PHP: 5.2.6
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12. --
  13. -- Base de datos: `XXXXX`
  14. --
  15.  
  16. -- --------------------------------------------------------
  17.  
  18. --
  19. -- Estructura de tabla para la tabla `inmuebles`
  20. --
  21.  
  22. CREATE TABLE `inmuebles` (
  23.   `Id` int(11) NOT NULL auto_increment,
  24.   `foto_a` varchar(15) default NULL,
  25.   `foto_b` varchar(15) default NULL,
  26.   `foto_c` varchar(15) default NULL,
  27.   `foto_d` varchar(15) default NULL,
  28.   `foto_e` varchar(15) default NULL,
  29.   `foto_f` varchar(15) default NULL,
  30.   `ciudad` varchar(15) default NULL,
  31.   `zona` varchar(15) default NULL,
  32.   `rangoArea` varchar(255) default NULL,
  33.   `barrio` varchar(30) default NULL,
  34.   `direccion` varchar(30) default NULL,
  35.   `num_matricula` varchar(30) default NULL,
  36.   `tipo` varchar(15) default NULL,
  37.   `valor` decimal(19,0) default NULL,
  38.   `rango` varchar(255) default NULL,
  39.   `area` varchar(10) default NULL,
  40.   `habitaciones` int(11) default NULL,
  41.   `codigo_inm` varchar(15) default NULL,
  42.   `Cod_Metro` varchar(255) default NULL,
  43.   `contacto` varchar(15) default NULL,
  44.   `nombre` varchar(30) default NULL,
  45.   `tel` double default NULL,
  46.   `obs` text,
  47.   PRIMARY KEY  (`Id`)
  48. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
  49.  
  50. --
  51. -- Volcar la base de datos para la tabla `inmuebles`
  52. --
  53.  
  54. INSERT INTO `inmuebles` VALUES (1, '2010-08-08 13:15:12', 'bna001a.jpg', 'bna001b.jpg', 'bna001c.jpg', 'bna001d.jpg', 'bna001e.jpg', 'bna001f.jpg', 'Bogota', 'norte', NULL, 'Bosques de san francisco', 'Av. La lajas 134-98', 'AO988776666899', 'Casas', 600000000, 'mas de 600m', '1500', 8, 'ABN001', NULL, 'Particular', 'Maria Pinilla', 3168103040, 'La pintura es reciente, la reja esta reparada el jardin en perfecto estado');
  55. INSERT INTO `inmuebles` VALUES (2, '2010-08-08 13:15:12', 'bna002a.jpg', 'bna002b.jpg', 'bna002c.jpg', 'bna002d.jpg', 'bna002e.jpg', 'bna002f.jpg', 'Bogota', 'sur', NULL, 'Acacias del jordan', 'Calle 123 No. 34-09', 'D0099231', 'Apartamentos', 340000000, '301-400m', '890', 6, 'ABN002', NULL, 'Particular', 'Orlando Rojas', 3106785438, 'Todo bien');
  56. INSERT INTO `inmuebles` VALUES (3, '2010-08-08 13:15:12', 'bna003a.jpg', 'bna002b.jpg', 'bna002c.jpg', 'bna002d.jpg', 'bna002e.jpg', 'bna002f.jpg', 'Bogota', 'sur', NULL, 'Jardines de la colina', 'Calle 90 No. 78-56', 'DH675TR', 'Apartamentos', 39000000, '301-400m', '3900', 9, 'ABN003', NULL, 'Particular', 'Monica Rios', 3123444556, 'Apartamento tipo Loft, un año de construído, como nuevo, bien situado,cerca estación trasmilenio MAZUREN,vias de acceso, Av. Boyacá, Autopista Norte, Cra. 52, éxito Colina. Acabados en madera de buen gusto, edificio con gimnasio, salón social, zonas verdes, parqueadero para visitantes, paseo comercial adjunto, edificio inteligente. Propietario directo, precio negociable');
  #10 (permalink)  
Antiguo 09/08/2010, 19:50
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

bueno no se si lo hice bien, la verdad necesito de su ayuda porque esto me esta volviendo loco no se como se hace, la pagina actualmente da error y el ejemplo de lo que deseo hacer esta en el siguiente link http://www.metrocuadrado.com/servlet...rInmueblesSolr
que no es otra cosa que un formulario de dos campos que dice ORDENAR POR el primer textbox nombre de campo y el segundo textbox asc o desc y boton ordenar.
mil gracias por su ayuda.
  #11 (permalink)  
Antiguo 09/08/2010, 20:09
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Ordenar consulta

ha, esto es otra voz, bueno pues el problema es este
tu tienes

Código PHP:
$query_Recordset1 "SELECT * FROM inmuebles order by $_GET['field'] $_GET['order']"
pero pues esto da problema con las comillas, así que cambialo a esto

Código PHP:
$query_Recordset1 "SELECT * FROM inmuebles order by ".$_GET['field']." ".$_GET['order']; 
esto soluciona el error PERO te mostrara ahora un error de mysql, porque??
porque no has hecho el punto 2 que te comente en anterior post

Cita:
"2. validar que si no se ha obtenido nada en $_GET['field'] ni en $_GET['order'] le asigne a estas valores por defecto. y en caso contrario pues que use los valores que lleguen"
lo cual puede manejarse de este modo

Código PHP:
if(!isset($_GET['field'])){
 
$_GET['field']='Id';

y pues podría manejarse lo mismo para order si se quiere aunque no es necesario pues mysql usa asc por omisión haciendo a un lado el $_GET['order']

prueba y comentas
saludos

__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com
  #12 (permalink)  
Antiguo 09/08/2010, 21:45
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

hola multiprogramador buenas noches, me sale este error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

ya te muestro el codigo como me quedo
  #13 (permalink)  
Antiguo 09/08/2010, 21:46
Avatar de 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. ?>
  #14 (permalink)  
Antiguo 09/08/2010, 22:09
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

YAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!! SOLUCIONADOOOOOOOOOOOOOOOOOOOO JAJAJAJAJAJAJAJAJA GRACIAS Y MIL GRACIAAAAAASSSSSSSSSS AMIGOOOOOOOO MULTIPROGRAMADOOOOORRRR

la verdad mi viejo eres una gran persona, tener pasiencia con migo para solucionarme este problema, no tengo palabaras para darte las gracias, desde ya estoy en deuda con tigo asi que ya puedes contar con un amigo, no se a donde te encuentras, yo estoy en colombia mi correo es [email protected] quiero mostrarte mi trabajo al finalizarlo para que veas cual importante fue tu ayuda........MIL GRACIAS AMIGO

cambios al codigo que te puse aqui arriba el if que tenia en la linea 9 lo puse en la 3 y ya!!!
  #15 (permalink)  
Antiguo 10/08/2010, 09:09
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

multiprogramador, mira que cuando fui a la pagina real donde quiero montar el orden a la consulta y aplique los cambios que me sugeriste me sale error, esa pagina no es tan sencilla como el ejemplo en el que trabajamos porque es la pagina real, debe ser algo muy minimo, mira te pongo el codigo sin los cambios que me enseñaste y mas abajo el mismo codigo con el if en la linea 3 y las variables en el ORDER BY, que pena mi hermano y grs.
  #16 (permalink)  
Antiguo 10/08/2010, 09:10
Avatar de 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.  
  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['ciudad'])) {
  45.   $colname_Recordset1 = $_GET['ciudad'];
  46. }
  47. $colpara_Recordset1 = "-1";
  48. if (isset($_GET['zona'])) {
  49.   $colpara_Recordset1 = $_GET['zona'];
  50. }
  51. $coltype_Recordset1 = "-1";
  52. if (isset($_GET['tipo'])) {
  53.   $coltype_Recordset1 = $_GET['tipo'];
  54. }
  55. $colrang_Recordset1 = "-1";
  56. if (isset($_GET['rango'])) {
  57.   $colrang_Recordset1 = $_GET['rango'];
  58. }
  59. mysql_select_db($database_conbanca, $conbanca);
  60. $query_Recordset1 = sprintf("SELECT inmuebles.foto_a, inmuebles.foto_b, inmuebles.foto_c, inmuebles.foto_d, inmuebles.foto_e, inmuebles.foto_f, inmuebles.ciudad, inmuebles.zona, inmuebles.barrio, inmuebles.direccion, inmuebles.tipo, inmuebles.valor, inmuebles.rango, inmuebles.area, inmuebles.habitaciones, inmuebles.codigo_inm, inmuebles.obs FROM inmuebles WHERE inmuebles.ciudad LIKE %s  AND inmuebles.zona LIKE %s  AND inmuebles.tipo LIKE %s  AND inmuebles.rango LIKE %s ORDER BY inmuebles.barrio", GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($colpara_Recordset1, "text"),GetSQLValueString($coltype_Recordset1, "text"),GetSQLValueString($colrang_Recordset1, "text"));
  61. $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
  62. $Recordset1 = mysql_query($query_limit_Recordset1, $conbanca) or die(mysql_error());
  63. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  64.  
  65. if (isset($_GET['totalRows_Recordset1'])) {
  66.   $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
  67. } else {
  68.   $all_Recordset1 = mysql_query($query_Recordset1);
  69.   $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
  70. }
  71. $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
  72.  
  73. $queryString_Recordset1 = "";
  74. if (!empty($_SERVER['QUERY_STRING'])) {
  75.   $params = explode("&", $_SERVER['QUERY_STRING']);
  76.   $newParams = array();
  77.   foreach ($params as $param) {
  78.     if (stristr($param, "pageNum_Recordset1") == false &&
  79.         stristr($param, "totalRows_Recordset1") == false) {
  80.       array_push($newParams, $param);
  81.     }
  82.   }
  83.   if (count($newParams) != 0) {
  84.     $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  85.   }
  86. }
  87. $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
  88. ?>
  89. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  90. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  91. <!-- saved from url=(0014)about:internet -->
  92. <html xmlns="http://www.w3.org/1999/xhtml">
  93. <head>
  94. <title>BANCA CENTRAL INMOBILIARIA CONVIERTA SU ARRIENDO EN CASA PROPIA!!!</title>
  95. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  96. <style type="text/css">td img {display: block;}body {
  97.     margin-left: 0px;
  98.     margin-top: 0px;
  99.     margin-right: 0px;
  100.     margin-bottom: 0px;
  101. }
  102. </style>
  103. <!--Fireworks CS3 Dreamweaver CS3 target.  Created Sun Aug 08 21:13:53 GMT-0500 2010-->
  104. <script language="JavaScript1.2" type="text/javascript">
  105. <!--
  106. function MM_preloadImages() { //v3.0
  107.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  108.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  109.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  110. }
  111. //-->
  112. </script>
  113. <link href="imgs/bacanciSt.css" rel="stylesheet" type="text/css" />
  114. </head>
  115. <body>
  116. <table width="100%" border="0" cellspacing="0" cellpadding="3">
  117.   <tr>
  118.     <td width="219"><img src="imgs/Página 1.jpg" width="219" height="31" /></td>
  119.     <td colspan="2"><table width="10%" border="0" align="right" cellpadding="0" cellspacing="0">
  120.       <tr>
  121.         <td nowrap="nowrap"><span class="textoN">Usted encontro </span><span class="encabN"><?php echo $totalRows_Recordset1 ?> <?php echo $row_Recordset1['tipo']; ?></span></td>
  122.       </tr>
  123.     </table></td>
  124.   </tr>
  125.   <tr>
  126.     <td height="40"><table width="10%" border="0" cellpadding="0" cellspacing="0">
  127.       <tr>
  128.         <td nowrap="nowrap" class="textoN">Registros <?php echo ($startRow_Recordset1 + 1) ?> a <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> de <?php echo $totalRows_Recordset1 ?></td>
  129.       </tr>
  130.     </table></td>
  131.     <td width="450"><form id="form1" name="form1" method="get" action="result2.php">
  132.       <label>
  133.         <select name="field" id="field">
  134.           <option>Seleccione un campo</option>
  135.           <option value="fecha">fecha</option>
  136.           <option value="barrio">barrio</option>
  137.           <option value="direccion">direccion</option>
  138.           <option value="codigo_inm">codigo_inm</option>
  139.         </select>
  140.       </label>
  141.       <label>
  142.         <select name="order" id="order" method="get">
  143.           <option selected="selected">Orden</option>
  144.           <option value="ASC">Ascendente</option>
  145.           <option value="DESC">Descendente</option>
  146.         </select>
  147.       </label>
  148.       <label>
  149.         <input type="submit" name="button" id="button" value="Enviar" />
  150.       </label>
  151.     </form></td>
  152.     <td width="213"><table border="0" align="right">
  153.       <tr>
  154.         <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  155.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border="0" /></a>
  156.           <?php } // Show if not first page ?></td>
  157.         <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  158.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border="0" /></a>
  159.           <?php } // Show if not first page ?></td>
  160.         <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  161.           <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>
  162.           <?php } // Show if not last page ?></td>
  163.         <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  164.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border="0" /></a>
  165.           <?php } // Show if not last page ?></td>
  166.       </tr>
  167.     </table></td>
  168.   </tr>
  169. </table>
  170. <?php do { ?>
  171.   <table width="100%" border="0" cellpadding="3" cellspacing="0" class="contmapa">
  172.     <tr>
  173.       <td width="152" rowspan="3" valign="top" bgcolor="#85C226"><a href="result3.php?codigo_inm=<?php echo $row_Recordset1['codigo_inm']; ?>"><img src="photos/<?php echo $row_Recordset1['foto_a']; ?>" width="152" height="100" border="0" /></a></td>
  174.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Barrio</td>
  175.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Valor venta</td>
  176.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Area</td>
  177.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Habit.</td>
  178.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Código</td>
  179.       <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  180.     </tr>
  181.     <tr>
  182.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['barrio']; ?></td>
  183.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN">$ <?php echo $row_Recordset1['valor']; ?></td>
  184.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['area']; ?> &nbsp;mts2</td>
  185.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['habitaciones']; ?></td>
  186.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['codigo_inm']; ?></td>
  187.       <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  188.     </tr>
  189.     <tr class="textoN">
  190.       <td colspan="5" valign="top" bgcolor="#FFFFFF" class="linSup">mm</td>
  191.       <td align="center" bgcolor="#FFFFFF"><table width="10%" border="0" align="center" cellpadding="0" cellspacing="0">
  192.         <tr>
  193.           <td><a href="result3.php?codigo_inm=<?php echo $row_Recordset1['codigo_inm']; ?>"><img src="imgs/ingresar.png" width="100" height="25" border="0" /></a></td>
  194.           </tr>
  195.       </table></td>
  196.     </tr>
  197.   </table>
  198.   <br />
  199. <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  200. </body>
  201. </html>
  202. <?php
  203. mysql_free_result($Recordset1);
  204. ?>
  #17 (permalink)  
Antiguo 10/08/2010, 09:13
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

Y ESTE ES EL CODIGO CON LOS CAMBIOS

Código PHP:
Ver original
  1. <?php require_once('Connections/conbanca.php'); ?>
  2. <?php
  3. if(!isset($_GET['field'])){
  4.  $_GET['field']='Id';
  5. }
  6. if (!function_exists("GetSQLValueString")) {
  7. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  8. {
  9.   if (PHP_VERSION < 6) {
  10.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  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. $currentPage = $_SERVER["PHP_SELF"];
  38.  
  39. $maxRows_Recordset1 = 10;
  40. $pageNum_Recordset1 = 0;
  41. if (isset($_GET['pageNum_Recordset1'])) {
  42.   $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
  43. }
  44. $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
  45.  
  46. $colname_Recordset1 = "-1";
  47. if (isset($_GET['ciudad'])) {
  48.   $colname_Recordset1 = $_GET['ciudad'];
  49. }
  50. $colpara_Recordset1 = "-1";
  51. if (isset($_GET['zona'])) {
  52.   $colpara_Recordset1 = $_GET['zona'];
  53. }
  54. $coltype_Recordset1 = "-1";
  55. if (isset($_GET['tipo'])) {
  56.   $coltype_Recordset1 = $_GET['tipo'];
  57. }
  58. $colrang_Recordset1 = "-1";
  59. if (isset($_GET['rango'])) {
  60.   $colrang_Recordset1 = $_GET['rango'];
  61. }
  62. mysql_select_db($database_conbanca, $conbanca);
  63. $query_Recordset1 = sprintf("SELECT inmuebles.foto_a, inmuebles.foto_b, inmuebles.foto_c, inmuebles.foto_d, inmuebles.foto_e, inmuebles.foto_f, inmuebles.ciudad, inmuebles.zona, inmuebles.barrio, inmuebles.direccion, inmuebles.tipo, inmuebles.valor, inmuebles.rango, inmuebles.area, inmuebles.habitaciones, inmuebles.codigo_inm, inmuebles.obs FROM inmuebles WHERE inmuebles.ciudad LIKE %s  AND inmuebles.zona LIKE %s  AND inmuebles.tipo LIKE %s  AND inmuebles.rango LIKE %s ORDER BY" .$_GET['field']." ".$_GET['order'];, GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($colpara_Recordset1, "text"),GetSQLValueString($coltype_Recordset1, "text"),GetSQLValueString($colrang_Recordset1, "text"));
  64. $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
  65. $Recordset1 = mysql_query($query_limit_Recordset1, $conbanca) or die(mysql_error());
  66. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  67.  
  68. if (isset($_GET['totalRows_Recordset1'])) {
  69.   $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
  70. } else {
  71.   $all_Recordset1 = mysql_query($query_Recordset1);
  72.   $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
  73. }
  74. $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
  75.  
  76. $queryString_Recordset1 = "";
  77. if (!empty($_SERVER['QUERY_STRING'])) {
  78.   $params = explode("&", $_SERVER['QUERY_STRING']);
  79.   $newParams = array();
  80.   foreach ($params as $param) {
  81.     if (stristr($param, "pageNum_Recordset1") == false &&
  82.         stristr($param, "totalRows_Recordset1") == false) {
  83.       array_push($newParams, $param);
  84.     }
  85.   }
  86.   if (count($newParams) != 0) {
  87.     $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  88.   }
  89. }
  90. $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
  91. ?>
  92. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  93. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  94. <!-- saved from url=(0014)about:internet -->
  95. <html xmlns="http://www.w3.org/1999/xhtml">
  96. <head>
  97. <title>BANCA CENTRAL INMOBILIARIA CONVIERTA SU ARRIENDO EN CASA PROPIA!!!</title>
  98. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  99. <style type="text/css">td img {display: block;}body {
  100.     margin-left: 0px;
  101.     margin-top: 0px;
  102.     margin-right: 0px;
  103.     margin-bottom: 0px;
  104. }
  105. </style>
  106. <!--Fireworks CS3 Dreamweaver CS3 target.  Created Sun Aug 08 21:13:53 GMT-0500 2010-->
  107. <script language="JavaScript1.2" type="text/javascript">
  108. <!--
  109. function MM_preloadImages() { //v3.0
  110.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  111.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  112.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  113. }
  114. //-->
  115. </script>
  116. <link href="imgs/bacanciSt.css" rel="stylesheet" type="text/css" />
  117. </head>
  118. <body>
  119. <table width="100%" border="0" cellspacing="0" cellpadding="3">
  120.   <tr>
  121.     <td width="219"><img src="imgs/Página 1.jpg" width="219" height="31" /></td>
  122.     <td colspan="2"><table width="10%" border="0" align="right" cellpadding="0" cellspacing="0">
  123.       <tr>
  124.         <td nowrap="nowrap"><span class="textoN">Usted encontro </span><span class="encabN"><?php echo $totalRows_Recordset1 ?> <?php echo $row_Recordset1['tipo']; ?></span></td>
  125.       </tr>
  126.     </table></td>
  127.   </tr>
  128.   <tr>
  129.     <td height="40"><table width="10%" border="0" cellpadding="0" cellspacing="0">
  130.       <tr>
  131.         <td nowrap="nowrap" class="textoN">Registros <?php echo ($startRow_Recordset1 + 1) ?> a <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> de <?php echo $totalRows_Recordset1 ?></td>
  132.       </tr>
  133.     </table></td>
  134.     <td width="450"><form id="form1" name="form1" method="get" action="result2.php">
  135.       <label>
  136.         <select name="field" id="field">
  137.           <option>Seleccione un campo</option>
  138.           <option value="fecha">fecha</option>
  139.           <option value="barrio">barrio</option>
  140.           <option value="direccion">direccion</option>
  141.           <option value="codigo_inm">codigo_inm</option>
  142.         </select>
  143.       </label>
  144.       <label>
  145.         <select name="order" id="order" method="get">
  146.           <option selected="selected">Orden</option>
  147.           <option value="ASC">Ascendente</option>
  148.           <option value="DESC">Descendente</option>
  149.         </select>
  150.       </label>
  151.       <label>
  152.         <input type="submit" name="button" id="button" value="Enviar" />
  153.       </label>
  154.     </form></td>
  155.     <td width="213"><table border="0" align="right">
  156.       <tr>
  157.         <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  158.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border="0" /></a>
  159.           <?php } // Show if not first page ?></td>
  160.         <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  161.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border="0" /></a>
  162.           <?php } // Show if not first page ?></td>
  163.         <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  164.           <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>
  165.           <?php } // Show if not last page ?></td>
  166.         <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  167.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border="0" /></a>
  168.           <?php } // Show if not last page ?></td>
  169.       </tr>
  170.     </table></td>
  171.   </tr>
  172. </table>
  173. <?php do { ?>
  174.   <table width="100%" border="0" cellpadding="3" cellspacing="0" class="contmapa">
  175.     <tr>
  176.       <td width="152" rowspan="3" valign="top" bgcolor="#85C226"><a href="result3.php?codigo_inm=<?php echo $row_Recordset1['codigo_inm']; ?>"><img src="photos/<?php echo $row_Recordset1['foto_a']; ?>" width="152" height="100" border="0" /></a></td>
  177.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Barrio</td>
  178.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Valor venta</td>
  179.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Area</td>
  180.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Habit.</td>
  181.       <td nowrap="nowrap" bgcolor="#85C226" class="encabN">Código</td>
  182.       <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  183.     </tr>
  184.     <tr>
  185.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['barrio']; ?></td>
  186.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN">$ <?php echo $row_Recordset1['valor']; ?></td>
  187.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['area']; ?> &nbsp;mts2</td>
  188.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['habitaciones']; ?></td>
  189.       <td nowrap="nowrap" bgcolor="#FFFFFF" class="textoN"><?php echo $row_Recordset1['codigo_inm']; ?></td>
  190.       <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  191.     </tr>
  192.     <tr class="textoN">
  193.       <td colspan="5" valign="top" bgcolor="#FFFFFF" class="linSup">mm</td>
  194.       <td align="center" bgcolor="#FFFFFF"><table width="10%" border="0" align="center" cellpadding="0" cellspacing="0">
  195.         <tr>
  196.           <td><a href="result3.php?codigo_inm=<?php echo $row_Recordset1['codigo_inm']; ?>"><img src="imgs/ingresar.png" width="100" height="25" border="0" /></a></td>
  197.           </tr>
  198.       </table></td>
  199.     </tr>
  200.   </table>
  201.   <br />
  202. <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  203. </body>
  204. </html>
  205. <?php
  206. mysql_free_result($Recordset1);
  207. ?>
  #18 (permalink)  
Antiguo 10/08/2010, 09:13
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

da este error

Parse error: syntax error, unexpected ';' in C:\AppServ\www\bancaci\result2.php on line 63
  #19 (permalink)  
Antiguo 10/08/2010, 09:49
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Ordenar consulta

bueno no lei todo tu codigo pero el error te lo dic claro tienes un ; que no se esperaba en esa linea podrias especificar cual es esa linea para ver si se ve ya q como dices el error es minimo suerte
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #20 (permalink)  
Antiguo 10/08/2010, 09:55
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

HOLA CARLOS MUCHAS GRACIAS POR TU RESPUESTA, CADA DIA VOY APRENDIENDO MAS DE PHP GRACIAS A UDS LOS PROFESIONALES LA LINEA 63 ES TODA LA COSNULTA AQUI TE LA PONGO.

Código PHP:
Ver original
  1. $query_Recordset1 = sprintf("SELECT inmuebles.foto_a, inmuebles.foto_b, inmuebles.foto_c, inmuebles.foto_d, inmuebles.foto_e, inmuebles.foto_f, inmuebles.ciudad, inmuebles.zona, inmuebles.barrio, inmuebles.direccion, inmuebles.tipo, inmuebles.valor, inmuebles.rango, inmuebles.area, inmuebles.habitaciones, inmuebles.codigo_inm, inmuebles.obs FROM inmuebles WHERE inmuebles.ciudad LIKE %s  AND inmuebles.zona LIKE %s  AND inmuebles.tipo LIKE %s  AND inmuebles.rango LIKE %s ORDER BY" .$_GET['field']." ".$_GET['order'];, GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($colpara_Recordset1, "text"),GetSQLValueString($coltype_Recordset1, "text"),GetSQLValueString($colrang_Recordset1, "text"));
  #21 (permalink)  
Antiguo 10/08/2010, 10:09
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Ordenar consulta

bueno fijate despues del $_GET['order'] pones un ; que terminaria tu linea ese es el que tienes de mas y no soy profecional apernas estoy comenzando en este mundo pero tengo un magister en ekivocarme en ese tipo de cosas jaja suerte
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #22 (permalink)  
Antiguo 10/08/2010, 10:12
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Ordenar consulta

Hola
bueno, no he hecho pruebas la verdad pero me atrevo a decir que tal vez
es el ; que tienes luego del $_GET['order'], pues aquí no es solo esa línea sino parámetros que usas en sprintf (cosa que si mal no recuerdo antes no se tenía)

prueba y comentas
saludos

Cita:
Iniciado por oscarios Ver Mensaje
HOLA CARLOS MUCHAS GRACIAS POR TU RESPUESTA, CADA DIA VOY APRENDIENDO MAS DE PHP GRACIAS A UDS LOS PROFESIONALES LA LINEA 63 ES TODA LA COSNULTA AQUI TE LA PONGO.

Código PHP:
Ver original
  1. $query_Recordset1 = sprintf("SELECT inmuebles.foto_a, inmuebles.foto_b, inmuebles.foto_c, inmuebles.foto_d, inmuebles.foto_e, inmuebles.foto_f, inmuebles.ciudad, inmuebles.zona, inmuebles.barrio, inmuebles.direccion, inmuebles.tipo, inmuebles.valor, inmuebles.rango, inmuebles.area, inmuebles.habitaciones, inmuebles.codigo_inm, inmuebles.obs FROM inmuebles WHERE inmuebles.ciudad LIKE %s  AND inmuebles.zona LIKE %s  AND inmuebles.tipo LIKE %s  AND inmuebles.rango LIKE %s ORDER BY" .$_GET['field']." ".$_GET['order'];, GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($colpara_Recordset1, "text"),GetSQLValueString($coltype_Recordset1, "text"),GetSQLValueString($colrang_Recordset1, "text"));
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com
  #23 (permalink)  
Antiguo 10/08/2010, 10:25
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

hola multiprogramador si tienes razon en el ejemplo anterior no estaba el sprintf que no tengo idea que es, quite el ; y la pagina abre perfecto, resulta que la pagina es el resultado de una consulta, cuando abre en la direccion del navegador sale esto ej:
Código HTML:
Ver original
  1. http://localhost:88/bancaci/result2.php?ciudad=Bogota&zona=sur&tipo=Apartamentos&rango=301-400m&imageField.x=38&imageField.y=10
osea que me muestra la lista con los inmuebles que arrojo la consulta, pero cuando le doy ordenar por ej barrio y orden ASC me borra lo que hay arriba y obviamente la pagina queda sin resultados, ahora si yo cuando la pagina abre le agrego arriba la variable y el resultado
Código HTML:
Ver original
  1. field=codigo_inm&order=DESC
a todo lo que hay del ordenar por,,,, funciona osea le doy enter y el organiza como le dije
osea si le agrego arriba le doy enter funciona
Código HTML:
Ver original
  1. http://localhost:88/bancaci/result2.php?ciudad=Bogota&zona=sur&tipo=Apartamentos&rango=301-400m&field=codigo_inm&order=DESC&imageField.x=38&imageField.y=10
osea necesito que el formulario ordenar por no me borre lo que hay arriba en la barra de direcciones sino que agrege los valores. ESPERO HABERME HECHO ENTENDER MI VIEJO GRS.
  #24 (permalink)  
Antiguo 10/08/2010, 10:43
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Ordenar consulta

bueno, eso pasa porque el resto de parámetros no lo estas enviando en el formulario o si los agregaste al formulario? si no estan, agrega campos hidden al formulario con los mismos nombres de las variables de url y le das el valor de $_GET, así por ej

Código HTML:
Ver original
  1. //campos hidden del form
  2. <input type='hidden' name='zona' value='<?php echo $_GET['zona']'/>

y listo, cuando se envie el form estas variables serán agregadas a la url
prueba y comentas
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com
  #25 (permalink)  
Antiguo 10/08/2010, 12:58
Avatar de oscarios  
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Ordenar consulta

bueno rtifico lo dicho ERES UNA GRAN PERSONA mil y mil gracias por tu ayuda multiprogramador y a ti carlos por tu ayuda. un abrazo desde Colombia.

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:47.