创建joomla模块以执行简单查询并显示结果

Besides the tables of joomla, I create my own table in the same database joomla!

Now I wanted to create a module, which made ​​the selection of this table and show. How can I do this!

Table FRUITS

ID | NAME
1 | apple
2 | orange
3 | banana

I have already created the structure of the module! Now I lack the build file:

  • helper.php
  • tmpl / default.php

Try this,

Inside your helper.php

function GetDetails(){
  $db = JFactory::getDBO();
  $sql= "SELECT * FROM FRUITS";
  $db->setQuery($sql);
  $db->query();
  $res = $db->loadAssocList();
  return $res;
}

and in your mod_ file have call to this function like

$result = class_name :: GetDetails();
//$result is available in your default.php

For more about module development in joomla.

Hopes its help you..

Just in case you don't need to really build a complete new module and you just want some PHP output in a module position you might give the Sourcerer module (http://www.nonumber.nl/extensions/sourcerer) a try. This module allows to execute PHP code at any module position in the context of a joomla module.

If you need more sophisticated rules on which pages your module should be active (e.g. depending on the user group), you should have a look at the "Advanced Module Manager" module from the same site.