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 5 years 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 5 years 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
Grid 4 PHP Framework
 
Minera Altos answered 5 years ago

Yes!  Opt2 work perfectly 4me.

thank u!  Mr Abu.

Your Answer

1 + 11 =

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

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?