Display the value from a reference table, rather than foreign key

QuestionsDisplay the value from a reference table, rather than foreign key
Carla Granberg asked 4 months ago

In the table I am using for the phpgrid, one of the fields is a foreign key to a reference table. Rather than displaying the key value in the cell, I want to display the value from the reference table.

For example, rather than displaying season_id = “1”; which is a foreign key to the reference table “seasons”, I want to display “Fall”, which is the value in the reference table associated with the primary key of “1”,

Another way to illustrate, is I want to use code like this below,  but not for Search Options, instead for the cell’s display value:

/ Fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values(“select distinct season_id as k, season_descr as v from seasons”);
$col[“stype”] = “select”;
$col[“searchoptions”] = array(“value” => $str, “separator” => “:”, “delimiter” => “;”);

What would be the array attribute to use instead of “searchoptions”?

2 Answers
Carla answered 4 months ago

Solved it myself, with another read through of the documentation. //season $col = array(); $col[\\\”title\\\”] = \\\”Season\\\”; $col[\\\”name\\\”] = \\\”season_id\\\”; $col[\\\”width\\\”] = \\\”20\\\”; $col[\\\”editable\\\”] = true; $col[\\\”edittype\\\”] = \\\”select\\\”; $col[\\\”editoptions\\\”] = array(\\\”value\\\”=>\\\’1:Fall;2:Winter;3:Spring\\\’); $cols[] = $col;

Abu answered 4 months ago

Refer these demos:

  1. method 1: https://www.gridphp.com/demo/demos/promo/index.phps line 112-212
  2. method 2: https://www.gridphp.com/demo/demos/appearance/dropdown.phps 104-123

These demos uses database to load values. If you want static, you can use above as in docs.

Your Answer

12 + 1 =

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?