Ext.: http://xuliewei.cn/archives/3071
Mainly about how to set up in the background to a database table additions and deletions, if there is a coincidence, if there is improper welcome to point out
1. Build a table with 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. Then create the file
File list:
./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. Document source code
menu_jianyannav.php
- <?php
- $menu [' Global '][]=array (' menu_jianyannav_mytest ', ' jianyannav_mytest ');//in ' Global ' definition menu menu_jianyannav_mytest ”
- ?>
lang_admincp_jianyannav.php
- <?php
- $extend _lang=array (' menu_jianyannav_mytest ' = ' Jianyan ');//define a name for the background menu
- $GLOBALS [' Admincp_actions_normal '][]= ' jianyannav ';//define the event file for the background menu
- ' 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 ("Delete succeeded", ' action=jianyannav&mod=list ');
- }
- Include_once Template ("Jianyancp/list");
- ?>
List.htm
- <div id= "CT" >
- <div class = "BM" >
- <table border=1px>
- <tr><td><b> category id</b></td><td><b> Parent category id</b></td><td> <b> Category name </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= "Delete" >
- </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= "edit" >
- </form>
- </td>
- </tr>
- <!--{/loop}-->
- <!--{else}-->
- <p> no data for the time being </p>
- <!--{/if}-->
- </table>
- </div>
- </div>
publish.php
- <?php
- if (!defined (' In_discuz '))
- {
- Exit ("Access denied");
- }
- if (!$_g[' uid '))
- {
- ShowMessage (' Sorry, not yet logged in, cannot be published ');
- }
- 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, "); Intercept 150 bytes of content
- $lbname = Cutstr (Dhtmlspecialchars (stripslashes ($_post[' lbname ')), 150, "); Intercept 150 bytes of content
- if (! $lbid)
- {
- Db::query ("INSERT into".) Db::table (' jianyanxmlb '). " (lbid,flbid,lbname) VALUES (null, ' ". $flbid." ', ' ". $lbname." ') ");
- Cpmsg ("Publishing Success", ' 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 ("Editorial success", ' action=jianyannav&mod=list ');
- }
- }
- Include_once Template ("Jianyancp/publish");
- ?>
Publish.htm
- <div id= "CT" >
-
- <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> parent category Id:</b><input name= "Flbid" id= "Flbid" value= $xmlb [0][' Flbid ']><br>
- <b> category name: </b><input name= "Lbname" id= "Lbname" value= $xmlb [0][' Lbname ']><br>
- <input type= "Submit" name= "Submit" value= "POST" style= "Float:left" ><br>
- </form>
- </div>
discuzX2.5 background Operations Custom database tables