Hallo Leute, ich steh zur Zeit voll auf dem Schlauch.
Ich komm hier nicht weiter. Folgendes:
Ich hab 2 Tabellen. In der 1. Tabelle existieren nur die Grunddaten eines Wertpapieres. In der 2. Tabelle werden täglich die Kurse zu den Wertpapieren eingetragen. Soweit sogut. Das funktioniert alles.
Aber im Frontend sehe ich nun für jeden Tag den Kurs zum dazugehörigen Wertpapier. Ich weiß nicht, wie ich es anstellen kann, dass zum Wertpapier immer nur der letzte Kurs angezeigt wird. Zur Zeit wird alles angezeigt.
Kann mir jemand auf die Sprünge helfen?
Hier sind meine Models:
Dieses holt alle Informationen zum Wertpapier aus der DB:
PHP-Code:
class MarketPriceModel extends \Model
{
/**
* Table name
* @var string
*/
protected static $strTable = 'tl_market_price';
public static function findAllByPublished($offset, $limit, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.published=?");
$arrOptions = array('order'=>"$t.sorting asc", 'offset'=>$offset, 'limit'=>$limit);
return static::findBy($arrColumns, 1, $arrOptions);
}
}
Dieses holt die Kurse aus der Datenbank
PHP-Code:
class MarketCourseModel extends \Model
{
/**
* Table name
* @var string
*/
protected static $strTable = 'tl_market_course';
public static function findAllByPublished($wid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.wid=?");
$arrOptions = array('order' => "$t.date desc");
return static::findBy($arrColumns, $wid, $arrOptions);
}
}
Und das ist dann mein Modul:
PHP-Code:
protected function compile()
{
\System::loadLanguageFile('tl_market_price');
$objTemplate = new \FrontendTemplate(($this->market_template ? $this->market_template : 'mod_market_price'));
$limit = 4;
$offset = 0;
$result_wertpapier = \MarketPriceModel::findAllByPublished($offset, $limit);
foreach ($result_wertpapier as $wertpapier_result)
{
$result_course = \MarketCourseModel::findAllByPublished($wertpapier_result->id);
foreach($result_course as $course_result)
{
$market[] = array
(
'title' => specialchars($wertpapier_result->title),
'title_short' => specialchars($wertpapier_result->title_short),
'course' => specialchars($course_result->share),
'date' => $course_result->date,
);
}
}
$objTemplate->wertpapier = $market;
$this->Template->markets = $objTemplate->parse();
}
Und jetzt noch das Template
HTML-Code:
<?php foreach ($this->wertpapier as $market): ?>
<ul class="result_min">
<li>
<div class="title"><?= $market['title_short']; ?><?= $market['course']; ?> <?= date($GLOBALS['TL_CONFIG']['dateFormat'], $market['date']); ?></div>
</li>
</ul>
<?php endforeach; ?>
Kann mir bitte jemand helfen?
Lesezeichen