inner join – error: missing column

Questionsinner join – error: missing column
Thomas asked 12 months ago

Hello there,

maybe I’m blind, but I can’t see what I’m doing wrong. Have an “inner join db-query”, and ‘am getting an error when trying to update an entry. All selections are displayed correctly in grid.

I have this code (snippet):
$g->select_command = "select p.products_id,p.products_quantity,p.products_model,p.products_price,p.products_price*1.19 as vatprice,p.products_date_added,p.products_last_modified,p.products_ordered,s.products_name,s.language_id,s.products_viewed from products p
inner join products_description s on s.products_id = p.products_id WHERE language_id = '2'";

// this db table will be used for add,edit,delete
$g->table = “products”;

// you can customize your own columns …
$col = array();
$col[“title”] = “ID”;
$col[“name”] = “products_id”;
$col[“width”] = “12”;
$col[“editable”] = false;
$cols[] = $col;

$col = array();
$col[“title”] = “Artikel Bezeichnung”;
$col[“name”] = “products_name”;
$col[“width”] = “80”;
$col[“editable”] = true;
$col[“align”] = “right”;
$col[“search”] = true;
$cols[] = $col;
…..

When trying to edit a row I get this error:

Couldn’t execute query. Unknown column ‘products_name’ in ‘field list’ – UPDATE products SET `products_name`=’Antennenverstärker 4-fach – CATV – Rückkanal’,`products_quantity`=’100.0000′,`products_model`=’tv-vsbk-rk’,`products_price`=’15.5378′,…..

As you can see I have 2 tables, set as “p” and “s”. The column ‘products_name’ exists in “s”.
Do I have any mistake in my syntax?

1 Answers
Abu Ghufran Staff answered 12 months ago

By default datagrid do updates on the table provided by ->table property. If you wish to update multiple table or have some custom code logic, you can use on_update event. Refer docs: https://www.gridphp.com/docs/grid-events/

Sample code for your case below:

$e["on_update"] = array("update_prod", null, true);
$g->set_events($e);

function update_prod($data)
{
	// update join table
	global $g;
	$g->execute_query("UPDATE products_description SET products_name = '".$data["products_name"]."' WHERE products_id = ".$data["products_id"]);

	// remove field not to update main table
	unset($data["products_name"]);
}
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

9 + 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?