ti incollo paro paro lo script...
considera che è un source di un ajax.
Codice PHP:
<?php
//include the information needed for the connection to MySQL data base server.
// we store here username, database and password
include("../../connect.inc.php");
// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
// we should set the appropriate header information. Do not forget this.
header("Content-type: text/xml;charset=iso-8859-1");
$type = $_GET['type'];
switch ($type) {
case 'delete':
//recupero l'id
$id = $_GET['id'];
$SQL = "UPDATE utenti SET obsoleto = 1 where id = " . $id . ";";
$result = mysql_query($SQL) or die(mysql_error($db));
break;
case 'update':
break;
case 'insert':
break;
case 'select':
$page = $_GET['page'];
// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];
// sorting order - at first time sortorder
$sord = $_GET['sord'];
// if we not pass at first time index use the first column for the index or what you want
if (!$sidx) {
$sidx = 1;
}
// calculate the number of rows for the query. We need this for paging the result
$result = mysql_query("SELECT COUNT(1) AS count FROM utenti");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$count = $row['count'];
// calculate the total pages for the query
if ($count > 0 && $limit > 0) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) {
$page = $total_pages;
}
// calculate the starting position of the rows
$start = $limit * $page - $limit;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if ($start < 0) {
$start = 0;
}
//modifica per gestione ricerca
if (trim($_GET['searchString']) == "") {
// the actual query for the grid data
$SQL = "SELECT b.id as id,b.cognome as cognome,b.nome as nome, b.societa as societa,
if(a.obsoleto=0,1,0) as attivo, a.amministratore as amministratore
FROM utenti a,clienti b
WHERE a.idcliente = b.id
ORDER BY $sidx $sord LIMIT $start , $limit";
} else {
if ($_GET['searchField'] == 'id') {
$_GET['searchField'] = 'b.id';
}
if ($_GET['searchField'] == 'attivo') {
$_GET['searchField'] = 'a.obsoleto';
if ($_GET['searchString'] == '1') {
$_GET['searchString'] = '0';
} else {
$_GET['searchString'] = '1';
}
}
switch ($_GET['searchOper']) {
case 'eq'://(uguale stretto)
$filter = "lower(" . $_GET["searchField"] . ") = '" . ($_GET["searchString"]) . "'";
break;
case 'cn': //(contiene)
$filter = "lower(" . $_GET["searchField"] . ") like '%" . ($_GET["searchString"]) . "%'";
break;
default:
$filter = "lower(" . $_GET['searchField'] . ") like '%'";
break;
}
$filter = strtolower($filter);
$SQL = "SELECT b.id as id,b.cognome as cognome,b.nome as nome, b.societa as societa,
if(a.obsoleto=0,1,0) as attivo, a.amministratore as amministratore
FROM utenti a,clienti b
WHERE a.idcliente = b.id
AND " . $filter . "
ORDER BY $sidx $sord LIMIT $start , $limit";
}
$result = mysql_query($SQL) or die(mysql_error($db));
$s = "<?xml version='1.0' encoding='iso-8859-1'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";
// be sure to put text data in CDATA
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$s .= "<row id='" . $row['id'] . "'>";
$s .= "<cell>" . $row['id'] . "</cell>";
$s .= "<cell>" . $row['cognome'] . "</cell>";
$s .= "<cell>" . $row['nome'] . "</cell>";
$s .= "<cell>" . $row['societa'] . "</cell>";
$s .= "<cell>" . $row['attivo'] . "</cell>";
$s .= "<cell>" . $row['amministratore'] . "</cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
break;
default:
break;
}
?>
naturalmente il punto in fondo allo script
Codice PHP:
// be sure to put text data in CDATA
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
non verrà mai soddisfatto.