|
亲注册登录道勤网-可以查看更多帖子内容哦!(包涵精彩图片、文字详情等)请您及时注册登录-www.daoqin.net
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖主要讲述如何在后台建立对某数据库表的增删查该,如有雷同纯属巧合、如有不妥欢迎指出
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" class="wp cl">
- <h1 class="mt">检验项目类别-<!--{if $_G[uid]}--><a href="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="{FORMHASH}">
- <input name="lbid" id="lbid" type="hidden" value=$xmlb['lbid']>
- <input type="submit" name="submitdel" value="删除" >
- </form>
- </td>
- <td>
- <form method="post" action="admin.php?action=jianyannav&mod=publish">
- <input type="hidden" name="formhash" id="formhash" value="{FORMHASH}">
- <input name="lbid" id="lbid" type="hidden" value=$xmlb['lbid']>
- <input type="submit" name="submitedit" value="编辑" >
- </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" class="wp cl">
- <h1 class="mt"><a href="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="{FORMHASH}">
- <input type="hidden" name="lbid" id="lbid" value=$xmlb[0]['lbid']>
- <b>父类别ID:</b><input name="flbid" id="flbid" value=$xmlb[0]['flbid']><br>
- <b>类别名称:</b><input name="lbname" id="lbname" value=$xmlb[0]['lbname']><br>
- <input type="submit" name="submit" value="发表" style="float:left"><br>
- </form>
- </div>
复制代码 新人发帖、多多指教
道勤主机提供365天*24小时全年全天无休、实时在线、零等待的售后技术支持。竭力为您免费处理您在使用道勤主机过程中所遇到的一切问题!
如果您是道勤主机用户,那么您可以通过QQ【792472177】、售后QQ【59133755】、旺旺【诠释意念】、微信:q792472177免费电话、后台提交工单这些方式联系道勤主机客服!
如果您不是我们的客户也没问题,点击页面最右边的企业QQ在线咨询图标联系我们并购买后,我们为您免费进行无缝搬家服务,让您享受网站零访问延迟的迁移到道勤主机的服务! |
|