Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

Consulta MSSQL con TOP rango de registros para uso del jqgrid

Estas en el tema de Consulta MSSQL con TOP rango de registros para uso del jqgrid en el foro de SQL Server en Foros del Web. Hola ante todo y agradecerles de ante mano mi problema consiste en que estoy utilizando el jqgrid con jquery mysql y php y teniendo encuenta ...
  #1 (permalink)  
Antiguo 16/12/2011, 11:47
Avatar de rafaely2011  
Fecha de Ingreso: septiembre-2011
Ubicación: Sancti Spiritus
Mensajes: 10
Antigüedad: 12 años, 5 meses
Puntos: 0
Pregunta Consulta MSSQL con TOP rango de registros para uso del jqgrid

Hola ante todo y agradecerles de ante mano mi problema consiste en que estoy utilizando el jqgrid con jquery mysql y php y teniendo encuenta los demos y tutoriales de la red he echo mi primer ejemplo jqgrid q me muestra los datos de una tabla en una base dato mysql ahora bien a la hora de implementar el mismo ejemplo pero en una base dato sql server 2000 me trae algunos problemas a la hora de mostrar los datos en el grid y al cambiar de pagina me sigue mostrando los mismo datos cargados y todo por la siguiente consulta me parece a mi

con esta consulta en mysql me pincha bien

Código:
$SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader ORDER BY $sidx $sord LIMIT $start , $limit";
pero a la hora de cambiar para MSSQL hago lo siguiente

Código:
$SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader ORDER BY $sidx $sord ";
de esta forma me muestra los datos pero no me cambia de paginas ya probe con otras variantes adaptandolas a mi cogigo

Código:
 SELECT * FROM (SELECT TOP $start *
    FROM (SELECT TOP $limit *
    FROM invheader
    ORDER BY [invid] ASC) AS tbl1
    ORDER BY invid DESC) AS tbl2
    ORDER BY $sidx $sord ASC
pero el archivo php me devuelve el siguiente error

Código:
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near '*'. (severity 15)
haa aclarar que la consulta anterior la proble en el servidor y me devuelve bien los datos en MSSQL


POR FAVOR AYUDENME quiero continuar el uso del jqgrid pero con mssql que el tipo de base datos q uso en mi empresa

GRACIAS DE ANTE MANO
  #2 (permalink)  
Antiguo 16/12/2011, 13:25
Avatar de Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 7 meses
Puntos: 774
Respuesta: Consulta MSSQL con TOP rango de registros para uso del jqgrid

podrias poner la sentencia completa??

SELECT * FROM (SELECT TOP $start *
FROM (SELECT TOP $limit *
FROM invheader
ORDER BY [invid] ASC) AS tbl1
ORDER BY invid DESC) AS tbl2
ORDER BY $sidx $sord ASC

ya que $start no se si es un valor o es el top 10.

Saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me
  #3 (permalink)  
Antiguo 16/12/2011, 14:58
Avatar de rafaely2011  
Fecha de Ingreso: septiembre-2011
Ubicación: Sancti Spiritus
Mensajes: 10
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: Consulta MSSQL con TOP rango de registros para uso del jqgrid

Si libras aqui te va el archivo php gracias por tu rapida atencion

<?php
include("dbconfig.php");

$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;

// connect to the MySQL database server
$db = mssql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mssql_error());

// select the database
mssql_select_db($database) ;

// calculate the number of rows for the query. We need this for paging the result
$result = mssql_query("SELECT COUNT(*) AS count FROM invheader");
$row = mssql_fetch_array($result,MSSQL_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;

// the actual query for the grid data
$SQL = " SELECT * FROM (SELECT TOP $start *
FROM (SELECT TOP $limit *
FROM invheader
ORDER BY [invid] ASC) AS tbl1
ORDER BY invid DESC) AS tbl2
ORDER BY $sidx $sord ASC ";
//$SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mssql_query( $SQL )or die("Couldnt execute query.".mssql_error());

// we should set the appropriate header information. Do not forget this.
header("Content-type: text/xml;charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$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 = mssql_fetch_array($result,MSSQL_ASSOC)) {
$s .= "<row id='". $row[invid]."'>";
$s .= "<cell>". $row[invid]."</cell>";
$s .= "<cell>". $row[invdate]."</cell>";
$s .= "<cell>". $row[amount]."</cell>";
$s .= "<cell>". $row[tax]."</cell>";
$s .= "<cell>". $row[total]."</cell>";
$s .= "<cell><![CDATA[". $row[note]."]]></cell>";
$s .= "</row>";
}
$s .= "</rows>";

echo $s;
?>
  #4 (permalink)  
Antiguo 19/12/2011, 09:02
Avatar de rafaely2011  
Fecha de Ingreso: septiembre-2011
Ubicación: Sancti Spiritus
Mensajes: 10
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: Consulta MSSQL con TOP rango de registros para uso del jqgrid

Ya logre que me mostrara los datos pero al cambiar el orden me invierte todos los datos el decir yo tengo 18 registros se supone q si yo muestro 10 cuando le hago click ordenar por cualquier columna se me siga mostrando los mismo 10 pero organizados por la columna deseada sin embargo me lo hace de los 18 registros es como q no me esta teniendo en cuenta la cantidad de registro seleccionada por favor ayudenme haaaa la consulta que tenahora es la siguiente
Código:
---
$SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader ORDER BY $sidx $sord";
---
  #5 (permalink)  
Antiguo 19/12/2011, 15:28
Avatar de Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 7 meses
Puntos: 774
Respuesta: Consulta MSSQL con TOP rango de registros para uso del jqgrid

Ponle un select top x from tabla order by $columna $orden
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me

Etiquetas: jqgrid, mssql, rango, registros, select, server, sql, tabla, top
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.
Tema Cerrado

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 23:10.