Buy Now
Sign in

populate dropdown from table via php

emrahsevgi , February 12 2019, 22:29
E
emrahsevgi 34
February 12 2019, 22:29 #383845
Hi;
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):
<?php
$results=array();
$this->data["party"] = $this->get("read_data3.party");
$results= $this->data["party"]["case_id"];
echo $results;
?>
But this code does not show anyting. What is my mistake in this code?
thx
healyhatman 8
February 13 2019, 00:03 #383846
 1
 Answer
$this->data("fieldname")
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.
or
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 SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
emrahsevgi 34
February 13 2019, 08:26 #383861
thank you very much.