Buy Now
Sign in

populate dropdown from table via php

emrahsevgi , February 12 2019, 22:29
emrahsevgi 34
February 12 2019, 22:29 #383845
I want to fill dropdown from read_data function which has got Model IDs. Firstly I used Read_Data action but it is getting full a table row like:
[{"Party":{"case_id":"950678196"}}] I don't understand why it shown like this and I tried PHP.
I found some infos in faq and I wrote this code without foreach for test (PS Model ID is party):
$this->data["party"] = $this->get("");
$results= $this->data["party"]["case_id"];
echo $results;
But this code does not show anyting. What is my mistake in this code?
healyhatman 8
February 13 2019, 00:03 #383846
Round brackets: it's a function, not an array.
If you want to SET a data element you need
$this->data("fieldname", "value", true);
But I don't see why you would need to do that.
So your PHP code should be
foreach($this->get("read_data3") as $k=>$v) {
echo $v["party"]["case_id"];
BUT it actually doesn't need to be either of those. What you need is either
1) Set your read data action to "return an array of key/value pairs" and you can use that as your dropdown values.
2) If you absolutely MUST use PHP for whatever reason
 $array = array();
foreach($this->get("read_data3") as $row) {
$array[$row["model"]["field_you_want_as_value"]] = $row["model"]["field_you_want_as_label"];
return $array;
Web developer at - I DO NOT work for ChronoEngine!
Professional Work:
Custom CF / CC Plugins and Extensions:
emrahsevgi 34
February 13 2019, 08:26 #383861
thank you very much.