ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

populate dropdown from table via php

emrahsevgi 12 Feb, 2019
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 13 Feb, 2019
Answer
1 Likes
$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;
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com