首页 > 代码库 > discuzX2.5后台操作自定义数据库表
discuzX2.5后台操作自定义数据库表
转:http://xuliewei.cn/archives/3071
主要讲述如何在后台建立对某数据库表的增删查该,如有雷同纯属巧合、如有不妥欢迎指出
1.通过phpmyadmin建表
- CREATE TABLE IF NOT EXISTS `pre_jianyanxmlb` (
- `lbid` mediumint(8) unsigned NOT NULL auto_increment,
- `flbid` mediumint(8) unsigned NOT NULL default ‘0‘,
- `lbname` varchar(255) NOT NULL default ‘‘,
- PRIMARY KEY (`lbid`)
- ) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=28 ;
2.然后建立文件
文件列表:
./source/admincp/menu/menu_jianyannav.php
./source/language/lang_admincp_jianyannav.php
./source/admincp/admincp_jianyannav.php
./source/admincp/jianyannav/list.php
./source/admincp/jianyannav/publish.php
./template/default/jianyancp/list.htm
./template/default/jianyancp/publish.htm
3.文件源码
menu_jianyannav.php
- <?php
- $menu[‘global‘][]=array(‘menu_jianyannav_mytest‘,‘jianyannav_mytest‘);//在‘全局’global定义菜单“menu_jianyannav_mytest”
- ?>
lang_admincp_jianyannav.php
- <?php
- $extend_lang=array(‘menu_jianyannav_mytest‘=>‘jianyan的后台‘);//给后台菜单定义名称
- $GLOBALS[‘admincp_actions_normal‘][]=‘jianyannav‘;//给后台菜单定义事件文件
- ‘admincp_jianyannav.php’
- ?>
admincp_jianyannav.php
- <?php
- $Discuz=discuz_core::instance();
- $modarray=array(‘list‘,‘publish‘);
- $mod=!in_array($discuz->var[‘mod‘],$modarray)?‘list‘:$discuz->var[‘mod‘];
- $discuz->init();
- require ‘./source/admincp/jianyannav/‘.$mod.‘.php‘;
- ?>
list.php
- <?php
- if(!defined(‘IN_DISCUZ‘))
- {
- exit(‘Access denied‘);
- }
- $list=array();
- $query=DB::query("select * from ".DB::table(‘jianyanxmlb‘)." order by flbid,lbid");
- while($xmlb=DB::fetch($query))
- {
- $list[]=$xmlb;
- }
- if(submitcheck(‘submitdel‘))
- {
- $lbid=dhtmlspecialchars(stripslashes($_POST[‘lbid‘]));
- DB::query("delete from ".DB::table(‘jianyanxmlb‘)." where ".DB::field(‘lbid‘,$lbid));
- cpmsg("删除成功",‘action=jianyannav&mod=list‘);
- }
- include_once template("jianyancp/list");
- ?>
list.htm
- <div id="ct">
- <h1>检验项目类别-<!--{if $_G[uid]}--><a href="http://www.mamicode.com/admin.php?action=jianyannav&mod=publish">新增类别</a><!--{/if}--></h1>
- <div class ="bm">
- <table border=1px>
- <tr><td><b>类别ID</b></td><td><b>父类别ID</b></td><td><b>类别名称</b></td><td><b></b></td><td><b></b></td></tr>
- <!--{if $list}-->
- <!--{loop $list $xmlb}-->
- <tr>
- <td>$xmlb[‘lbid‘]</td>
- <td>$xmlb[‘flbid‘]</td>
- <td>$xmlb[‘lbname‘]</td>
- <td>
- <form method="post" action="admin.php?action=jianyannav&mod=list">
- <input type="hidden" name="formhash" id="formhash" value="http://www.mamicode.com/{FORMHASH}">
- <input name="lbid" id="lbid" type="hidden" value=http://www.mamicode.com/$xmlb[‘lbid‘]>
- <input type="submit" name="submitdel" value="http://www.mamicode.com/删除" >
- </form>
- </td>
- <td>
- <form method="post" action="admin.php?action=jianyannav&mod=publish">
- <input type="hidden" name="formhash" id="formhash" value="http://www.mamicode.com/{FORMHASH}">
- <input name="lbid" id="lbid" type="hidden" value=http://www.mamicode.com/$xmlb[‘lbid‘]>
- <input type="submit" name="submitedit" value="http://www.mamicode.com/编辑" >
- </form>
- </td>
- </tr>
- <!--{/loop}-->
- <!--{else}-->
- <p>暂时没有相关数据</p>
- <!--{/if}-->
- </table>
- </div>
- </div>
publish.php
- <?php
- if(!defined(‘IN_DISCUZ‘))
- {
- exit("Access denied");
- }
- if(!$_G[‘uid‘])
- {
- // showmessage(‘抱歉,尚未登录,不能发表‘);
- }
- if(submitcheck(‘submitedit‘))
- {
- $lbid=dhtmlspecialchars(stripslashes($_POST[‘lbid‘]));
- echo $lbid;
- $xmlb=DB::fetch_all("select * from ".DB::table(‘jianyanxmlb‘)." where ".DB::field(lbid,$lbid));
- echo $xmlb[0][‘lbid‘];
- echo $xmlb[0][‘flbid‘];
- echo $xmlb[0][‘lbname‘];
- }
- if(submitcheck(‘submit‘))
- {
- $lbid=dhtmlspecialchars(stripslashes($_POST[‘lbid‘]));
- $flbid = cutstr(dhtmlspecialchars(stripslashes($_POST[‘flbid‘])), 80, ‘‘); //截取150个字节的内容
- $lbname = cutstr(dhtmlspecialchars(stripslashes($_POST[‘lbname‘])), 150, ‘‘); //截取150个字节的内容
- if(!$lbid)
- {
- DB::query("insert into ".DB::table(‘jianyanxmlb‘)." (lbid,flbid,lbname) values (null,‘".$flbid."‘,‘".$lbname."‘)");
- cpmsg("发表成功",‘action=jianyannav&mod=list‘);
- }
- else
- {
- DB::query("update ".DB::table(‘jianyanxmlb‘)." set ".DB::field(flbid,$flbid)." , ".DB::field(lbname,$lbname)." where ".DB::field(lbid,$lbid));
- echo "update ".DB::table(‘jianyanxmlb‘)." set ".DB::field(flbid,$flbid)." , ".DB::field(lbname,$lbname)." where ".DB::field(lbid,$lbid);
- cpmsg("编辑成功",‘action=jianyannav&mod=list‘);
- }
- }
- include_once template("jianyancp/publish");
- ?>
publish.htm
- <div id="ct">
- <h1><a href="http://www.mamicode.com/admin.php?action=jianyannav&mod=list">检验项目类别-</a>新增类别</h1>
- <form method="post" action="admin.php?action=jianyannav&mod=publish">
- <input type="hidden" name="formhash" id="formhash" value="http://www.mamicode.com/{FORMHASH}">
- <input type="hidden" name="lbid" id="lbid" value=http://www.mamicode.com/$xmlb[0][‘lbid‘]>
- <b>父类别ID:</b><input name="flbid" id="flbid" value=http://www.mamicode.com/$xmlb[0][‘flbid‘]>
- <b>类别名称:</b><input name="lbname" id="lbname" value=http://www.mamicode.com/$xmlb[0][‘lbname‘]>
- <input type="submit" name="submit" value="http://www.mamicode.com/发表" style="float:left"><br>
- </form>
- </div>
discuzX2.5后台操作自定义数据库表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。