Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:07:36+00:00 2026-05-26T18:07:36+00:00

I have create a simple grid that retrieves data from a server through php.

  • 0

I have create a simple grid that retrieves data from a server through php. The number of rows in MYSQL database are 9.

I decide to change the rowNum option from rowNum:10 to rowNum:7 and see what will happen. As i expected 7 rows appeared on grid. The problem is that i can not see the rest 2. The pager bar hasn’t got a second page (Page 1 of 1 it says).
Then i add the recordtext option and set it to this recordtext: ‘{0} – {1} of {2}’.
Refresh the page and in the right down corner of the grid this text apeard “1 – 7 of 9”. That means that all of the data returned from the server but something going bad with pagination.

Let me post the code.

index.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Grid</title>

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.jqGrid.min.js"></script>


<style>
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style>


<script type="text/javascript">

$(function(){ 

  mygrid = $("#list");

  mygrid.jqGrid({
    url:'example1.php',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
    colModel :[ 
      {name:'invid', index:'invid', width:55}, 
      {name:'invdate', index:'invdate', width:90}, 
      {name:'amount', index:'amount', width:80, align:'right', search:true , stype:'select', searchoptions:{value:':All;8:8.00;6:6.00'}}, 
      {name:'tax', index:'tax', width:80, align:'right'}, 
      {name:'total', index:'total', width:80, align:'right', sortable:true}, 
      {name:'note', index:'note', width:150, search:true , align:'center'} 
    ],
    pager: '#pager',
    emptyrecords: "Nothing to display",
    recordtext: '{0} - {1} of {2}',
    rowNum:7,
    rowList:[7,9,11],
    viewrecords: true,
    caption: 'My first grid'

  });
  //Search button
  $("#bsdata").click(function(){ mygrid.jqGrid('searchGrid', {sopt:['eq'],top:300,caption:"test searching"} ); });
  // Search toolbar.
  mygrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "eq"});
  //NavBar
  mygrid.jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
}); 


</script>

</head>
<body>

<table id="list"><tr><td/></tr></table> 
<div id="pager"></div> 
<input type="BUTTON" id="bsdata" value="Search" />


</body>
</html>

and example1.php

<?php
$page = 1; // $_GET['page']; // get the requested page
$limit = 9; //$_GET['rows']; // get how many rows we want to have into the grid
$sidx = 'invid';//$_GET['sidx']; // get index row - i.e. user click to sort
$sord = 'invid';//$_GET['sord']; // get the direction
if(!$sidx) $sidx =1;

//array to translate the search type
$ops = array(
    'eq'=>'=', //equal
    'ne'=>'<>',//not equal
    'lt'=>'<', //less than
    'le'=>'<=',//less than or equal
    'gt'=>'>', //greater than
    'ge'=>'>=',//greater than or equal
    'bw'=>'LIKE', //begins with
    'bn'=>'NOT LIKE', //doesn't begin with
    'in'=>'LIKE', //is in
    'ni'=>'NOT LIKE', //is not in
    'ew'=>'LIKE', //ends with
    'en'=>'NOT LIKE', //doesn't end with
    'cn'=>'LIKE', // contains
    'nc'=>'NOT LIKE'  //doesn't contain
);
function getWhereClause($col, $oper, $val){
    global $ops;
    if($oper == 'bw' || $oper == 'bn') $val .= '%';
    if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
    if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
    return " WHERE $col {$ops[$oper]} '$val' ";
}
$where = ""; //if there is no search request sent by jqgrid, $where should be empty
$searchField = isset($_GET['searchField']) ? $_GET['searchField'] : false;
$searchOper = isset($_GET['searchOper']) ? $_GET['searchOper']: false;
$searchString = isset($_GET['searchString']) ? $_GET['searchString'] : false;
if ($_GET['_search'] == 'true') {
    $where = getWhereClause($searchField,$searchOper,$searchString);
}

// connect to the database
$dbhost = "localhost";
$dbuser = "user";
$dbpassword = "user123";
$database = "test";
$tablename = "invheader";
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
//mysql_set_charset('utf8',$database);
mysql_query("SET NAMES 'utf8'");
$result = mysql_query("SELECT COUNT(*) AS count FROM $tablename");
$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;

$start = $limit*$page - $limit; // do not put $limit*($page - 1)

$SQL = "SELECT invid, invdate, amount, tax, total, note FROM $tablename ".$where." ORDER BY $sidx, $sord LIMIT $start , $limit";

$result = mysql_query( $SQL ) or die("Couldn?t execute query.".mysql_error());

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8"); } else {
header("Content-type: text/xml;charset=utf-8");
}


$et = ">";

echo "<?xml version='1.0' encoding='utf-8'?$et\n";
echo "<rows>";
echo "<page>".$page."</page>";
echo "<total>".$total_pages."</total>";
echo "<records>".$count."</records>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    echo "<row id='". $row['invid']."'>";
    echo "<cell>". $row['invid']."</cell>";
    echo "<cell>". $row['invdate']."</cell>";
    echo "<cell>". $row['amount']."</cell>";
    echo "<cell>". $row['tax']."</cell>";
    echo "<cell>". $row['total']."</cell>";
    echo "<cell><![CDATA[". $row['note']."]]></cell>";
    echo "</row>";
}
echo "</rows>";
?>

Additionally tried to use this method but also nothing changed.
Any idea ? Can you give me some hints ?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:07:37+00:00Added an answer on May 26, 2026 at 6:07 pm

    So. The mistake was due to a noobish coding.

    As you can see in the top of php file i have this

    $page = 1; // $_GET[‘page’]; // get the requested page
    $limit = 9; //$_GET[‘rows’]; // get how many rows we want to have into the grid

    While the html file send rowNum: 7 in the php this number became 9 and that’s why it was saying Page 1 of 1.

    To solve the problem i just had to erase comments and use the $_GET method.

    Also i change what Oleg said.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to create a simple database in Access to collect some
I have a requirement to create a simple windows forms application that allows an
I'm trying to create a very simple REST server. I just have a test
I have some tables in a MySQL database to represent records from a sensor.
I have created a simple grid of divs by left floating them and an
I have been trying to create a simple program with Python which uses OpenCV
I have used following code to create a simple PDF file. It executes fine
I am about to create a simple demo in flash where I have 3
I'm trying to create a simple portfolio page. I have a list of thumbs
I want to create a simple COM component in VC++ 2008. I have created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.