You really should start by reading XoopsObject class located in XOOPS255/kernel/object.php
That is the heart of any module to do anything using database include search,sort,order,pagination,...
so you should stop writing these kind of codes:
le="color: #000000"><?php global $xoopsDB; $result= mysql_query("SELECT * FROM ".$xoopsDB->prefix("directory_info")." where name like '%" . $_POST['search'] . "%' or unit like '%" . $_POST['search'] . "%' or department like '%" . $_POST['search'] . "%' or position like '%" . $_POST['search'] . "%' ORDER BY name");
you should create the sql file for every table and start create a class for that table.
I recommend to see publisher as a very profesional module.
lets start with an example from publisher module.
we want to see how we can write a class for table publisher_categories in sql file.
at first you can see the table fields and structure in sql file:
http://svn.code.sf.net/p/xoops/svn/XoopsModules/publisher/trunk/publisher/sql/mysql.phple="color: #000000"><?php CREATE TABLE `PUBLISHER_categories` ( `categoryid` int(11) NOT NULL auto_increment, `parentid` int(11) NOT NULL default '0', `name` varchar(100) NOT NULL default '', `description` text NOT NULL, `image` varchar(255) NOT NULL default '', `total` int(11) NOT NULL default '0', `weight` int(11) NOT NULL default '1', `created` int(11) NOT NULL default '1033141070', `template` varchar(255) NOT NULL default '', `header` text NOT NULL, `meta_keywords` text NOT NULL, `meta_description` text NOT NULL, `short_url` varchar(255) NOT NULL default '', `moderator` int(6) NOT NULL default '0', PRIMARY KEY (`categoryid`), KEY parentid (parentid) ) ENGINE=MyISAM;
then see how to define the class:
the filename is category.php
http://svn.code.sf.net/p/xoops/svn/XoopsModules/publisher/trunk/publisher/class/category.phpyou can see how to define your fields:
le="color: #000000"><?php class PublisherCategory extends XoopsObject { /** * @var PublisherPublisher * @access public */ public $publisher = null; /** * @var array */ public $_categoryPath = false; /** * constructor */ public function __construct() { $this->publisher = PublisherPublisher::getInstance(); $this->initVar("categoryid", XOBJ_DTYPE_INT, null, false); $this->initVar("parentid", XOBJ_DTYPE_INT, null, false); $this->initVar("name", XOBJ_DTYPE_TXTBOX, null, true, 100); $this->initVar("description", XOBJ_DTYPE_TXTAREA, null, false, 255); $this->initVar("image", XOBJ_DTYPE_TXTBOX, null, false, 255); $this->initVar("total", XOBJ_DTYPE_INT, 1, false); $this->initVar("weight", XOBJ_DTYPE_INT, 1, false); $this->initVar("created", XOBJ_DTYPE_INT, null, false); $this->initVar("template", XOBJ_DTYPE_TXTBOX, null, false, 255); $this->initVar("header", XOBJ_DTYPE_TXTAREA, null, false); $this->initVar("meta_keywords", XOBJ_DTYPE_TXTAREA, null, false); $this->initVar("meta_description", XOBJ_DTYPE_TXTAREA, null, false); $this->initVar("short_url", XOBJ_DTYPE_TXTBOX, null, false, 255); $this->initVar("moderator", XOBJ_DTYPE_INT, null, false, 0); //not persistent values $this->initVar("itemcount", XOBJ_DTYPE_INT, 0, false); $this->initVar('last_itemid', XOBJ_DTYPE_INT); $this->initVar('last_title_link', XOBJ_DTYPE_TXTBOX); $this->initVar("dohtml", XOBJ_DTYPE_INT, 1, false); } /** * @param string $method * @param array $args * * @return mixed */ public function __call($method, $args) { $arg = isset($args[0]) ? $args[0] : null; return $this->getVar($method, $arg); }
then another class by extending XoopsPersistableObjectHandler for access to table:
le="color: #000000"><?php /** * Categories handler class. * This class is responsible for providing data access mechanisms to the data source * of Category class objects. * * @author marcan <marcan@notrevie.ca> * @package Publisher */ class PublisherCategoryHandler extends XoopsPersistableObjectHandler { /** * @var PublisherPublisher * @access public */ public $publisher = null; /** * @param null|object $db */ public function __construct(&$db) { $this->publisher = PublisherPublisher::getInstance(); parent::__construct($db, "publisher_categories", 'PublisherCategory', "categoryid", "name"); }
reviewing publisher module would be enough for everybody.
but you can see userlog as a simpler module.
http://svn.code.sf.net/p/xoops/svn/XoopsModules/userlog/trunk/userlog/see i defined one class for each table
userlog/class/log.php for mod_userlog_log table
userlog/class/setting.php for mod_userlog_set table
userlog/class/stats.php for mod_userlog_stats table
I want to write a tutorial "how to write a standard module for xoops" based on what i learnt from publisher module.