![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
27/04/2011, 07:02
|
| | Fecha de Ingreso: abril-2011
Mensajes: 39
Antigüedad: 13 años, 10 meses Puntos: 1 | |
Respuesta: Modificar registros de la base de datos perdón, copié otra página, a ver si ahora lo hago mejor......jeje
<?php
ini_set('max_execution_time', 600);
include("dbconfig.php");
// coment the above lines if php 5
include("JSON.php");
$json = new Services_JSON();
// end comment
$examp = $_REQUEST["q"]; //query number
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;
$sidx="Name";
if(isset($_GET["Nombre"])) $Nombre = $_GET['Nombre'];
else $Nombre = "";
if(isset($_GET["Apellido"])) $Apellido = $_GET['Apellido'];
else $Apellido = "";
if(isset($_GET["DNI"])) $DNI = $_GET['DNI'];
else $DNI = "";
if(isset($_GET["Empresa"])) $Empresa = $_GET['Empresa'];
else $Empresa = "";
if(isset($_GET["Visitada"])) $Visitada = $_GET['Visitada'];
else $Visitada = "";
if(isset($_GET["Asunto"])) $Asunto = $_GET['Asunto'];
else $Asunto = "";
if(isset($_GET["Registro"])) $Registro = $_GET['Registro'];
else $Registro = "";
if(isset($_GET["Acceso"])) $acceso = $_GET['Acceso'];
else $Acceso = "";
if(isset($_GET["Devolucion"])) $acceso = $_GET['Devolucion'];
else $Devolucion = "";
// Estas son las condiciones de busqueda del campo
$where = "WHERE 1=1";
if($Nombre!='') $where.= " AND Name LIKE '%$Nombre%'";
if($Apellido!='') $where.= " AND Surname LIKE '%$Apellido%'";
if($DNI!='') $where.= " AND DNI LIKE '%$DNI%'";
if($Empresa!='') $where.= " AND Company LIKE '%$Empresa%'";
if($Visitada!='') $where.= " AND Visited LIKE '%$Visitada%'";
if($Asunto!='') $where.= " AND Purpose LIKE '%$Asunto%'";
if($Registro!='') $where.= " AND Num_Registry LIKE '%$Registro%'";
if($Acceso!='') $where.= " AND Access_Card LIKE '%$Acceso%'";
if($Devolucion!='') $where.= " AND Card_Return LIKE '%$Devolucion%'";
// connect to the database
//$db = mysql_pconnect($dbhost, $dbuser, $dbpassword)
$db = mysql_pconnect("localhost", "root", "password")
or die("Connection Error: " . mysql_error());
mysql_select_db("inventario") or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM Entry ".$where);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
if ($limit<0) $limit = 0;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL="SELECT * FROM Entry ".$where." ORDER BY ID DESC, $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("No se pudo ejecutar la consulta.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[Name];
$responce->rows[$i]['cell']=array($row[Name],$row[Surname],$row[DNI],$row[Company],$row[Visited], $row[Purpose],$row[Num_Registry],$row[Access_Card],$row[Card_Return]);
$i++;
}
echo $json->encode($responce); // coment if php 5
//echo json_encode($responce);
mysql_close($db);
?> |