Page getting called twice causing two times query firing on database

QuestionsPage getting called twice causing two times query firing on database
Ansh asked 9 years ago

Hi i am facing very irritating issue my webpage is getting called twice.First time with plain url like

"localhost/test.php"

and second time with following parameter

"localhost/test.php?grid_id=list1&_search=false&nd=1456936160227&rows=20&jqgrid_page=1&sidx=1&sord=asc"

Now i tried this in core PHP as well in CodeIgnitor but giving same problem.
In case of CodeIgnitor my Controller function gets called twice causing entire process to go again.
Please help me to avoid autocallbacks or some workaround for it

3 Answers
Abu Ghufran answered 9 years ago

The grid is loaded with 2 server calls.

1) load the columns of grid.
2) do an ajax call, to load data of grid.

This is how it is designed and we can't remove it.

Ansh answered 9 years ago

Hi, Thanks for quick response.
I have no problem with that design but it act little differently than what you say
this is mysql log

2016-03-02T17:44:06 333 Connect webadmin@localhost on using TCP/IP
2016-03-02T17:44:06 333 Init DB vault
2016-03-02T17:44:06 333 Query SET NAMES 'utf8'
2016-03-02T17:44:07 333 Query SELECT * FROM user WHERE 1=1 LIMIT 1 OFFSET 0
2016-03-02T17:44:07 333 Quit
2016-03-02T17:44:09 334 Connect webadmin@localhost on using TCP/IP
2016-03-02T17:44:09 334 Init DB vault
2016-03-02T17:44:09 334 Query SET NAMES 'utf8'
2016-03-02T17:44:10 334 Query SELECT * FROM user WHERE 1=1 LIMIT 1 OFFSET 0
2016-03-02T17:44:10 334 Query SELECT count(*) as c FROM (SELECT * FROM user WHERE 1=1) pg_tmp
2016-03-02T17:44:10 334 Query SELECT * FROM user WHERE 1=1 ORDER BY 1 asc LIMIT 20 OFFSET 0
2016-03-02T17:44:10. 334 Quit

and this is my php code

<?php

$rootpath = $_SERVER['DOCUMENT_ROOT'];
$path =$rootpath. "/classes/phpgrid/";

include($rootpath."/classes/DBConnection.php");

DBConnect();//my class to connect to database

include($path."lib/inc/jqgrid_dist.php");
$g = new jqgrid();

$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>false, // allow/disallow edit
"delete"=>false, // allow/disallow delete
"rowactions"=>false, // show/hide row wise edit/del/save option
"export"=>true, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);

$grid_id = "list1";
$g->table="user";
// set database table for CRUD operation
$out = $g->render($grid_id);

?>

Am i doing anything wrong.Please guide me

Abu Ghufran answered 9 years ago

This is done 2 times as we need actual db field names for both calls.
2016-03-02T17:44:07 333 Query SELECT * FROM user WHERE 1=1 LIMIT 1 OFFSET 0
This is required to fetch db column names for grid.

2016-03-02T17:44:10 334 Query SELECT count(*) as c FROM (SELECT * FROM user WHERE 1=1) pg_tmp
2016-03-02T17:44:10 334 Query SELECT * FROM user WHERE 1=1 ORDER BY 1 asc LIMIT 20 OFFSET 0
These are one for total count of rows and other for data.

Your Answer

3 + 11 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?