3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1533 Views |
-
print array in template

7 March 2011 at 11:47pm
HI
how to foreach this array in template ?
public function produkty() {
$produkty_array = new DataObjectSet;$produkty = array();
$filter = "ParentID = $this->ID";
$data = DataObject::get('SiteTree', $filter);foreach ($data as $item) {
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
'KolorID','Filename'
);
$sqlQuery->from = array("ProduktKolory LEFT JOIN File ON ProduktKolory.KolorID = File.ID");
$sqlQuery->where = array("ProduktID = $item->ID");$results = $sqlQuery->execute();
foreach ($results as $row) {
$kolor['KolorID'] = $row['KolorID'];
$kolor['KolorURL'] = $row['Filename'];
$produkt[$item->ID][] = $kolor;
}
}
// echo '<pre>';
// print_r($produkt);
// echo '</pre>';$produkty_array->push(new ArrayData($produkt));
return $produkty_array;
}<pre>Array
(
[10] => Array
(
[0] => Array
(
[KolorID] => 24
[KolorURL] => assets/kolory/ico-color-blue.png
)[1] => Array
(
[KolorID] => 23
[KolorURL] => assets/kolory/ico-color.png
))
[16] => Array
(
[0] => Array
(
[KolorID] => 23
[KolorURL] => assets/kolory/ico-color.png
))
)
</pre>i need to do
<ul>
<% control produkty %>
<li>
$KolorID
<img src="$Filename" />
</li>
<% end_control %>
</ul> -
Re: print array in template

7 March 2011 at 11:59pm
the end result should be like this:
<li>
10
kolorID: 24
kolorURL: ....kolorID: 23
kolorURL: ....
</li><li>
16
kolorID: 23
kolorURL: ....
</li> -
Re: print array in template

8 March 2011 at 2:08am
how about something like...
public function produkty() {
//do stuff to get results into $results
$dos = new DataObjectSet();
foreach ($results as $row) {
foreach ($row as $key => $val) {
$do->$key = $val;
$dos->push($do);
}}}<ul>
<% control produkty %>
<li>
$KolorID
<img src="$Filename" />
</li>
<% end_control %>
</ul>
| 1533 Views | ||
|
Page:
1
|
Go to Top |


