SELECT Statement in Joomla TMPL default.php file
I'm developing a Joomla开发者_JAVA技巧 component. Where I have years, months and tour dates.
The idea is to have
2011 2012 2013 2014 (links) and let's say 2011 is active. below I have
sept, 2011
concert in sept #1; concert in sept #2; concert in sept #3;
oct, 2011
concert in oct #1; concert in oct #2; concert in oct #3;
nov, 2011
concert in nov #1; concert in nov #2; concert in nov #3;
I guess you can understand the display structure.
I have 1 table, and on my custom made page I would handle that with no problem. but I'm developing it on Joomla, so I'm a bit confused.
I have 1 function getYEAR that displays years and in Tmpl default.php I have foreach.
Now I created another function getMonth that displays months and it looks like this:
$now = date('Y');
$year = JRequest::getInt('year', $now);
$db =& JFactory::getDBO();
$query = "SELECT DISTINCT MONTH( date ), #__concert_month.monthname
FROM #__concert_info
JOIN #__concert_month ON #__concert_month.id = MONTH( date )
WHERE YEAR( date ) = {$year} AND date >= CURDATE( )
ORDER BY MONTH( date )";
$db->setQuery( $query );
$this->_month = $db->loadObjectList();
return $this->_month;
And it's fine. but the problem is that I want to SELECT tour places according to months, like I described above Month -> concerts, Month->concerts
Normally I would do
SElECT smth1
foreach1 (smth1 as smt1)
echo Monthname $id=smth1
SELECT smth2 WHERE MONTH( date ) = $id
foreach2(smth2 as smt2)
endforeach2
endforeach1
How can I have SELECT inside FOREACH in tmpl->default.php? Or is there any other solution?
It turns out that you can put SELECT
directly into the tmpl->default.php
file. I guess I was wrong somewhere yesterday, today it worked.
I still don't like the idea of putting SELECT
into default.php
, though (I'd prefer to put it in models, the way it should be).
精彩评论