On update, can't access to primary key

QuestionsOn update, can't access to primary key
ALÉN asked 8 years ago

Hello,

I'm trying to obtain the "id" on update, but when I tried to access the variable return "<a href= ".
Could you help me to fix it?

Thank you.

Code:

$col = array();
$col["title"] = "id"; // caption of column, can use HTML tags too
$col["name"] = "id"; // grid column name, same as db field or alias from sql
$col["width"] = "5"; // width on grid
$col["hidden"] = false;
$col["editable"] = false;
$col["viewable"] = true;
$col["link"] = "action.php?action=document&idCase={id}";
$cols[] = $col;

$e["on_update"] = array("update_case", null, false);
$grid->set_events($e);

function update_case($data) {
global $grid, $table;

$handle = fopen("temp.txt", "w");
foreach ($data["params"] as $key => $value) {
fwrite($handle, "Nombre: $key Valor: $value n");
}
fwrite($handle,$data["id"]);

fclose($handle);
}

6 Answers
Alén answered 8 years ago

Ok. If I comment this line:

$col["link"] = "action.php?action=document&idCase={id}";

the problem disappear. But I want to use this link in the column. Do you know how to fix it?

Thank you.

Abu Ghufran answered 8 years ago

You can create 2 column.
First with non-link and second with link.
and make first column as hidden:true.

First column is used in update so it will fix the query.
And second column will only be visible for your purpose.

Abu Ghufran answered 8 years ago

To bee more clear, 2 columns with same field id.

Alén answered 8 years ago

I tried something like that:

$col = array();
$col["title"] = "id"; // caption of column, can use HTML tags too
$col["name"] = "id"; // grid column name, same as db field or alias from sql
$col["width"] = "5"; // width on grid
$col["hidden"] = true;
$col["editable"] = false;
$col["viewable"] = false;
$cols[] = $col;

$col = array();
$col["title"] = "X"; // caption of column, can use HTML tags too
$col["name"] = "id"; // grid column name, same as db field or alias from sql
$col["width"] = "5"; // width on grid
$col["hidden"] = false;
$col["editable"] = false;
$col["viewable"] = true;
$col["link"] = "acciones.php?accion=generardocumento&idCaso={id}";
$cols[] = $col;

It's replicate the link in the two colums.

Abu Ghufran answered 8 years ago

Ok,

Try selecting this column in sql_command with different alias.=
e.g.

select id, id as id_link, ….

And name first column as id and second as id_link.

Alén answered 8 years ago

Perfect, thank you.

Your Answer

1 + 2 =

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?