How can I show in a column, information from another table.

QuestionsHow can I show in a column, information from another table.
Minera Altos de Punitaqui asked 1 month ago

Hi Phpgrid people! sorry, a noob question…

table A [ id, name, age ]     table B [ id, infotext ]

in app.php – with $g->table = “B”;

….

$col = array();

$col[“title”] = “Name”;

$col[“name”] = “name”;  (this data must be taken from table A with id PK)

How can I show in a column, information from another table (with a select sql on “formatoptions” ?)

thank u!!

2 Answers
Abu Ghufran Staff answered 1 month ago

Option1: Select grid data using SQL join in select_command. e.g.

$g->select_command = “SELECT a.name,a.age,b.id,b.infotext FROM b INNER JOIN a on a.id=b.id”;

Then on display, you can use above code.

Option2: You can still avoid using select_command and use dropdown to lookup from other table. IF a.id = b.id (PK,FK)

$col[“name”] = “id”;

$col[“edittype”] = “select”; // render as select
$str = $g->get_dropdown_values(“select id as k, name as v from A”);
$col[“editoptions”] = array(“value”=>$str);
$col[“formatter”] = “select”; // display label, not value

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Minera Altos answered 1 month ago

Yes!  Opt2 work perfectly 4me.

thank u!  Mr Abu.

Your Answer

2 + 10 =

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 / 5. Vote count:

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

Let us improve this post!