Reputation: 746
I am trying to make a simple module for joomla 2.5. Essentially I want to be able to have a dropdown list with a persons riding. Once selected. The information for that district office/personal office would show up in a div below the dropdown box.
I eventually would like to have a second drop down list that would allow the user to choose office phone, personal phone, office email, personal email, office address or personal address, after first selecting the riding. That decided info would show up below the two drop down boxes. So far I have the module setup and installed (structure is correct). Just don't have the proper code in my helper.php and tmpl/default.php
HELPER.PHP
<?php
// No Access
defined('_JEXEC') or die ;
//Add database Instance
$db = JFactory::getDBO();
//Pass in query
$query = "SELECT * FROM #__mlainfo";
//Run it
$db -> setQuery($query);
//Load it as an object into variable "$ridings"
$riding = $db -> loadObjectList();
DEFAULT.PHP
<?php defined('_JEXEC') or die; ?>
<div class="moduletable<?php echo $params->get( 'moduleclass_sfx' ) ?>">
<select>
<?php foreach ($riding as $riding_name => $ridings): ?>
<option value="<?php echo $riding_name ?>">
<?php endforeach; ?>
</select>
</div>
I realize I am only half way there. I get a select list to show up with this installed. However it just has 40 blank spaces. Any help would be appreciated.
All the info is stored in database with titles being;
riding(number), riding_name, full_name, off_address, per_address, off_email, per_email, off_phone, per_phone
Upvotes: 0
Views: 2416
Reputation: 3731
You just need to complete the option field:
<?php defined('_JEXEC') or die; ?>
<div class="moduletable<?php echo $params->get( 'moduleclass_sfx' ) ?>">
<select>
<?php foreach ($riding as $riding_name => $ridings): ?>
<option value="<?php echo $ridings->riding ?>"><?php echo $ridings->riding_name ?></option>
<?php endforeach; ?>
</select>
</div>
Upvotes: 1
Reputation: 7059
loadObjectList() returns an indexed array of PHP objects
<div class="moduletable<?php echo $params->get( 'moduleclass_sfx' ) ?>">
<select>
<?php foreach ($riding as $key => $ridings): ?>
<option value="<?php echo $ridings->riding?>"><?php echo $ridings->riding_name?></option>
<?php endforeach; ?>
</select>
</div>
http://docs.joomla.org/Accessing_the_database_using_JDatabase/1.5#loadObjectList.28.29
Hope this will help.
Upvotes: 2