Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/10/2010, 16:57
Avatar de oscarios
oscarios
 
Fecha de Ingreso: septiembre-2004
Mensajes: 186
Antigüedad: 19 años, 7 meses
Puntos: 2
Respuesta: Formulario de order by

PARTE 1
Código PHP:
Ver original
  1. <?php
  2. if(!isset($_GET['field'])){
  3.  $_GET['field']='Id';
  4. }
  5. if (!function_exists("GetSQLValueString")) {
  6. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  7. {
  8.   if (PHP_VERSION < 6) {
  9.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  10.   }
  11.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.  
  13.   switch ($theType) {
  14.     case "text":
  15.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.       break;    
  17.     case "long":
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  34.  
  35. if (!function_exists("GetSQLValueString")) {
  36. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  37. {
  38.   if (PHP_VERSION < 6) {
  39.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  40.   }
  41.   if(!isset($_GET['field'])){
  42.  $_GET['field']='Id';
  43. }
  44.  
  45.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  46.  
  47.   switch ($theType) {
  48.     case "text":
  49.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  50.       break;    
  51.     case "long":
  52.     case "int":
  53.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  54.       break;
  55.     case "double":
  56.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  57.       break;
  58.     case "date":
  59.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  60.       break;
  61.     case "defined":
  62.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  63.       break;
  64.   }
  65.   return $theValue;
  66. }
  67. }
  68.  
  69. if (!function_exists("GetSQLValueString")) {
  70. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  71. {
  72.   if (PHP_VERSION < 6) {
  73.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  74.   }
  75.  
  76. if(!isset($_GET['field'])){
  77.  $_GET['field']='Id';
  78. }
  79.  
  80.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  81.  
  82.   switch ($theType) {
  83.     case "text":
  84.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  85.       break;    
  86.     case "long":
  87.     case "int":
  88.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  89.       break;
  90.     case "double":
  91.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  92.       break;
  93.     case "date":
  94.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  95.       break;
  96.     case "defined":
  97.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  98.       break;
  99.   }
  100.   return $theValue;
  101. }
  102. }
  103.  
  104. $currentPage = $_SERVER["PHP_SELF"];
  105.  
  106. $maxRows_Recordset1 = 10;
  107. $pageNum_Recordset1 = 0;
  108. if (isset($_GET['pageNum_Recordset1'])) {
  109.   $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
  110. }
  111. $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
  112.  
  113. $colname_Recordset1 = "-1";
  114. if (isset($_GET['busca'])) {
  115.   $colname_Recordset1 = $_GET['busca'];
  116. }
  117. $colpara_Recordset1 = "-1";
  118. if (isset($_GET['busca2'])) {
  119.   $colpara_Recordset1 = $_GET['busca2'];
  120. }
  121. $coltype_Recordset1 = "-1";
  122. if (isset($_GET['busca3'])) {
  123.   $coltype_Recordset1 = $_GET['busca3'];
  124. }
  125. mysql_select_db($database_conbanca, $conbanca);
  126. $query_Recordset1 = sprintf("SELECT * FROM inmuebles WHERE ciudad LIKE %s AND zona LIKE %s AND tipo LIKE %s order by ".$_GET['field']." ".$_GET['order'], GetSQLValueString("%" . $colname_Recordset1 . "%", "text"),GetSQLValueString("%" . $colpara_Recordset1 . "%", "text"),GetSQLValueString("%" . $coltype_Recordset1 . "%", "text"));
  127. $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
  128. $Recordset1 = mysql_query($query_limit_Recordset1, $conbanca) or die(mysql_error());
  129. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  130.  
  131. if (isset($_GET['totalRows_Recordset1'])) {
  132.   $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
  133. } else {
  134.   $all_Recordset1 = mysql_query($query_Recordset1);
  135.   $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
  136. }
  137. $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
  138.  
  139. $queryString_Recordset1 = "";
  140. if (!empty($_SERVER['QUERY_STRING'])) {
  141.   $params = explode("&", $_SERVER['QUERY_STRING']);
  142.   $newParams = array();
  143.   foreach ($params as $param) {
  144.     if (stristr($param, "pageNum_Recordset1") == false &&
  145.         stristr($param, "totalRows_Recordset1") == false) {
  146.       array_push($newParams, $param);
  147.     }
  148.   }
  149.   if (count($newParams) != 0) {
  150.     $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  151.   }
  152. }
  153. $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
  154. ?>
__________________
oscariosdw