I want to use php variable as table for the phpGrid as code shown below:
$getRange=$_POST[‘game’];
……
……
$g->select_command = “select * from $getRange ” ;
$g->table = ” $getRange “;
……
……
it keeps given errors as follows:
Couldn’t execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE 1=1 LIMIT 1 OFFSET 0’ at line 1 – select * from WHERE 1=1 LIMIT 1 OFFSET 0
Please help me and thank you in advanced
Please refer this doc: https://www.gridphp.com/docs/misc-faqs/#q-how-to-load-grid-based-on-_post-data-from-other-page
You need to preserve this POSTed variable in session before using in query.
Thank you for the support but the error still persist as follows: Error as follows: Couldn\’t execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \’WHERE 1=1 LIMIT 1 OFFSET 0\’ at line 1 – select * from WHERE 1=1 LIMIT 1 OFFSET 0
Mysql Server version and my PHP/SQL code as you advised are as follows: mysql> select @@version; +————————-+ | @@version | +————————-+ | 5.5.62-0ubuntu0.14.04.1 | +————————-+
if (!empty($_POST[\”game\”]))
{ $_SESSION[\”game\”] = $_POST[\”game\”]; } $getRange = $_SESSION[\”game\”]; // assign to session variable echo $getRange; // print the table name on the screen $g->select_command = \”select * from $getRange \”; $g->table = \”$getRange\”; please help me and Thanks in advance
mysql version is 5.5.62-0ubuntu0.14.04.1
if (!empty($_POST[“game”]))
{
$_SESSION[“game”] = $_POST[“game”];
}
$getRange = $_SESSION[“game”]; // assign to session variable
echo $getRange; // print the table name on the screen
$g->select_command = “select * from $getRange “;
$g->table = “$getRange”;
Error as follows:
Couldn’t execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE 1=1 LIMIT 1 OFFSET 0’ at line 1 – select * from WHERE 1=1 LIMIT 1 OFFSET 0
Hello,
As regards to the previous error I have discovered that, the bug may come from library file located in /lib/inc/jqgrid_dist.php line 890, 893, 903 and 1395. please find below the code from the jqgrid_dist.php
Find below the code and please help me out.
885 // place group by at proper position in sql
886 if (($p = stripos($this->select_command,”GROUP BY”)) !== false)
887 {
888 $start = substr($this->select_command,0,$p);
889 $end = substr($this->select_command,$p);
890 $this->select_command = $start.” WHERE 1=1 “.$end;
891 }
892 else
893 $this->select_command .= ” WHERE 1=1″;
894 }
895
896 // re-adjust subqueries in sql
897 $this->select_command = $this->add_subsql($this->select_command,$matches_subsql);
898
899 // get sql column names by running nulled sql
900 if (!empty($this->internal[“sql”]))
901 $this->select_command = $this->internal[“sql”];
902
903 $sql = $this->select_command . ” LIMIT 1 OFFSET 0″;
904
905 $sql = $this->prepare_sql($sql,$this->db_driver);
906
907 $result = $this->execute_query($sql);
….
….
1385 * Common functions for db operations
1386 */
1387 function execute_query($sql,$data = false,$return=””)
1388 {
1389 if ($this->con)
1390 {
1391 $ret = $this->con->Execute($sql,$data);
1392 if (!$ret)
1393 {
1394 if ($this->debug)
1395 phpgrid_error(“Couldn’t execute query. “.$this->con->ErrorMsg().” – $sql”);
1396 else
1397 phpgrid_error($this->error_msg);
1398 }
1399