jqgrid - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: jqgrid (/showthread.php?tid=46537) |
jqgrid - El Forum - 11-04-2011 [eluser]Unknown[/eluser] Hello trying to make a basic exercise with jqGrid not get to show me the data, ie, shows me what is the design but not the data. I have tried in the file do a print_r jqgrid.php m but not display anything. GRATEFUL who could help me My code is as follows: vista - contenido3.php [code] <html> <head> <title>Principal</title> </head> <body> <h1>CLientes</h1> <table id="list"> </table> <div id="pager"> <p>Holaaaa</p> </div> </body> </html> jqgrid.php <?php //include the information needed for the connection to MySQL data base server. // we store here username, database and password // 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. $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; $db = mysql_connect('localhost', 'root', 'root') or die("Connection Error: " . mysql_error()); // select the database mysql_select_db('optinet') or die("Error connecting to db."); // calculate the number of rows for the query. We need this for paging the result $result = mysql_query("SELECT COUNT(*) AS count FROM clientes"); $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; // the actual query for the grid dat $SQL = "SELECT * FROM clientes"; $result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error()); print_r($result); // 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 = mysql_fetch_array($result,MYSQL_ASSOC)) { $s .= "<row id='". $row['DNI']."'>"; $s .= "<cell>". $row['Nombre']."</cell>"; $s .= "</row>"; } $s .= "</rows>"; echo $s; ?> controller <?php class Prueba1 extends CI_Controller { function index() { $this->load->view('includes/header'); $this->load->view('contenido3'); } } ?> vista header : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="es"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Optinet</title> <link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/> <link rel="stylesheet" type="text/css" href="css/960.css" media="screen"/> <link rel="stylesheet" type="text/css" href="css/text.css" media="screen"/> <link rel="stylesheet" type="text/css" href="css/reset.css" media="screen"/> <link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.16.custom.css" /> <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" /> [removed][removed] [removed][removed] [removed][removed] [removed] $(function(){ $("#list").jqGrid({ url:'jqgrid.php', datatype: 'xml', mtype: 'GET', colNames:['Dni','Nombre'], colModel :[ {name:'DNI', index:'DNI', width:55}, {name:'Nombre', index:'Nombre', width:90} ], pager: '#pager', rowNum:10, rowList:[10,20,30], viewrecords: true, gridview: true, caption: 'My first grid' }); }); [removed] </head> <body> thanks!!![\code] |