Custom Sql in "$codalbarantmp"

QuestionsCustom Sql in "$codalbarantmp"
fersan asked 10 years ago

I can see this variable
$grid["caption"] = "$codalbarantmp"; // caption of grid

// you can provide custom SQL query to display data

This sentence don't work

//$g->select_command = "SELECT * FROM (SELECT i.codalbaran, i.numlinea, c.referencia, c.descripcion, i.cantidad, i.importe FROM pedidoslineatmp i INNER JOIN articulos c ON i.codigo = c.codarticulo WHERE i.codalbaran='" .$codalbarantmp. "') o";

This sentence don't work

//$g->select_command = "SELECT i.codalbaran, i.numlinea, c.referencia, c.descripcion, i.cantidad, i.importe FROM pedidoslineatmp i, articulos c WHERE i.codigo = c.codarticulo AND i.codalbaran = '$codalbarantmp'";

this sentence works but the problem is fix.

$g->select_command = "SELECT * FROM (SELECT i.codalbaran, i.numlinea, c.referencia, c.descripcion, i.cantidad, i.importe FROM pedidoslineatmp i INNER JOIN articulos c ON i.codigo = c.codarticulo WHERE i.codalbaran=11909) o";

5 Answers
Abu Ghufran answered 10 years ago

Please refer faq: Q) How to load grid based on $_POST data from other page.

fersan answered 10 years ago

Yes I use GET from other page

<?php
include ("../conectar.php");
$codalbarantmp=$_POST["codalbarantmp"];
$modif=$_POST["modif"];
$tipuscaja=$_POST["tipuscaja"];
$retorno=0;
if ($modif<>1) {
if (!isset($codalbarantmp)) {
$codalbarantmp=$_GET["codalbarantmp"];
$retorno=1; }
if ($retorno==0 && $tipuscaja==1) {
$codfamilia=$_POST["codfamilia"];
$codarticulo=$_POST["codarticulo"];
$cajas=$_POST["cajas"];
$unidadescajas=$_POST["unidadescajas"];
$cantidad=$_POST["cantidad"];
$precio=$_POST["precio"];
$importe=$_POST["importe"];
$descuento=$_POST["descuento"];
$codubicacion=$_POST["codubicacion"];
$sel_insert="INSERT INTO pedidoslineatmp (codalbaran,numlinea,codigo,codfamilia,cajas,unidades_caja,cantidad,precio,importe,dcto,inv) VALUES ('$codalbarantmp','','$codarticulo','$codfamilia','$cajas','$unidadescajas','$cantidad','$precio','$importe','$descuento','$codubicacion')";
$rs_insert=mysql_query($sel_insert);

$query_tmp="SELECT * FROM cajlinea WHERE codcaja='$codarticulo' ORDER BY numlinea ASC";
$rs_tmp=mysql_query($query_tmp);
$contador=0;

while ($contador < mysql_num_rows($rs_tmp)) {
$codarticulo_caja=mysql_result($rs_tmp,$contador,"codigo");
$unidadescajas=mysql_result($rs_tmp,$contador,"unidades_caja");
$descuento1= ($descuento/100);
$cantidad=($cajas * $unidadescajas);
$importe= ($cantidad * $precio);
$importe=($importe-($importe * $descuento1));

$sel_insert="INSERT INTO pedidoslineatmp (codalbaran,numlinea,codigo,codfamilia,cajas,unidades_caja,cantidad,precio,importe,dcto,inv) VALUES ('$codalbarantmp','','$codarticulo_caja','$codfamilia','$cajas','$unidadescajas','$cantidad','$precio','$importe','$descuento','$codubicacion')";
$rs_insert=mysql_query($sel_insert);

$contador++;
}
}
}

/**
* PHP Grid Component
*
* @author Abu Ghufran <[email protected]> – http://www.phpgrid.org
*/

$conn = mysql_connect("localhost", "root", "***");
mysql_select_db("****");

mysql_query("SET NAMES 'utf8'");

include("../grid/inc/jqgrid_dist.php");

$col = array();
$col["title"] = "Id"; // caption of column
$col["name"] = "codalbaran, numlinea"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "10";
$col["hidden"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "Codalba"; // caption of column
$col["name"] = "codalbaran"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "10";
//$col["hidden"] = true;
$cols[] = $col;

$cols[] = $col;
$g = new jqgrid();
// $grid["url"] = ""; // your paramterized URL — defaults to REQUEST_URI
$grid["rowNum"] = 10; // by default 20
$grid["sortname"] = 'codalbaran'; // by default sort grid by this field
$grid["sortorder"] = "desc"; // ASC or DESC
$grid["caption"] = "$codalbarantmp"; // caption of grid
$grid["autowidth"] = true; // expand grid to screen width
$grid["multiselect"] = true; // allow you to multi-select through checkboxes

$g->set_options($grid);

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

// you can provide custom SQL query to display data
//$g->select_command = "SELECT * FROM (SELECT i.codalbaran, i.numlinea, c.referencia, c.descripcion, i.cantidad, i.importe FROM pedidoslineatmp i INNER JOIN articulos c ON i.codigo = c.codarticulo WHERE i.codalbaran='$codalbarantmp') o";

$g->select_command = "SELECT * FROM (SELECT i.codalbaran, i.numlinea, c.referencia, c.descripcion, i.cantidad, i.importe FROM pedidoslineatmp i INNER JOIN articulos c ON i.codigo = c.codarticulo WHERE i.codalbaran = '$codalbarantmp') o";

$g->table = "pedidoslineatmp";

// pass the cooked columns to grid
$g->set_columns($cols);

// generate grid output, with unique grid name as 'list1'
$out = $g->render("list1");

fersan answered 10 years ago

I've used the sentence

if (!empty($_POST["codalbarantmp"]))
{
$_SESSION["codalbarantmp"] = $_POST["codalbarantmp"];
}
$pid = $_SESSION["codalbarantmp"];

$grid["caption"] = "$pid"; // caption of grid… I can see VARIABLE but the sentence in custom Sql dont show nothing

$g->select_command = "SELECT * FROM (SELECT i.codalbaran, i.numlinea, c.referencia, c.descripcion, i.cantidad, i.importe FROM pedidoslineatmp i INNER JOIN articulos c ON i.codigo = c.codarticulo WHERE i.codalbaran = '$pid') o";

Abu Ghufran answered 10 years ago

Please make sure you are usng session_start(); call before using $_SESSION vars.

fersan answered 10 years ago

Yes, I don't add

session_start();
Now works perfect thanks for all.

Your Answer

16 + 15 =

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?