discuzX2.5 background Operations Custom database tables

Source: Internet
Author: User

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

    1. CREATE TABLE IF not EXISTS ' pre_jianyanxmlb ' (
    2. ' Lbid ' mediumint (8) unsigned not NULL auto_increment,
    3. ' Flbid ' mediumint (8) unsigned not NULL default ' 0 ',
    4. ' Lbname ' varchar (255) Not NULL default ' ',
    5. PRIMARY KEY (' lbid ')
    6. ) 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

    1. <?php
    2. $menu [' Global '][]=array (' menu_jianyannav_mytest ', ' jianyannav_mytest ');//in ' Global ' definition menu menu_jianyannav_mytest ”
    3. ?>

lang_admincp_jianyannav.php

    1. <?php
    2. $extend _lang=array (' menu_jianyannav_mytest ' = ' Jianyan ');//define a name for the background menu
    3. $GLOBALS [' Admincp_actions_normal '][]= ' jianyannav ';//define the event file for the background menu
    4. ' Admincp_jianyannav.php '
    5. ?>

admincp_jianyannav.php

    1. <?php
    2. $Discuz =discuz_core::instance ();
    3. $modarray =array (' list ', ' Publish ');
    4. $mod =!in_array ($discuz->var[' mod '), $modarray)? ' List ': $discuz->var[' mod ');
    5. $discuz->init ();
    6. Require './source/admincp/jianyannav/'. $mod. PHP ';
    7. ?>

list.php

    1. <?php
    2. if (!defined (' In_discuz '))
    3. {
    4. Exit (' Access denied ');
    5. }
    6. $list =array ();
    7. $query =db::query ("SELECT * from".) Db::table (' jianyanxmlb '). "ORDER by Flbid,lbid");
    8. while ($xmlb =db::fetch ($query))
    9. {
    10. $list []= $xmlb;
    11. }
    12. if (Submitcheck (' Submitdel '))
    13. {
    14. $lbid =dhtmlspecialchars (stripslashes ($_post[' lbid '));
    15. Db::query ("delete from".) Db::table (' jianyanxmlb '). "Where". Db::field (' Lbid ', $lbid));
    16. Cpmsg ("Delete succeeded", ' action=jianyannav&mod=list ');
    17. }
    18. Include_once Template ("Jianyancp/list");
    19. ?>

List.htm

  1. <div id= "CT" >
  2. <div class = "BM" >
  3. <table border=1px>
  4. <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>
  5. <!--{if $list}-->
  6. <!--{Loop $list $xmlb}-->
  7. <tr>
  8. <td> $xmlb [' Lbid ']</td>
  9. <td> $xmlb [' Flbid ']</td>
  10. <td> $xmlb [' Lbname ']</td>
  11. <td>
  12. <form method= "POST" action= "Admin.php?action=jianyannav&mod=list" >
  13. <input type= "hidden" name= "Formhash" id= "Formhash" value= "{Formhash}" >
  14. <input name= "Lbid" id= "Lbid" type= "hidden" value= $xmlb [' Lbid ']>
  15. <input type= "Submit" Name= "Submitdel" value= "Delete" >
  16. </form>
  17. </td>
  18. <td>
  19. <form method= "POST" action= "Admin.php?action=jianyannav&mod=publish" >
  20. <input type= "hidden" name= "Formhash" id= "Formhash" value= "{Formhash}" >
  21. <input name= "Lbid" id= "Lbid" type= "hidden" value= $xmlb [' Lbid ']>
  22. <input type= "Submit" Name= "SubmitEdit" value= "edit" >
  23. </form>
  24. </td>
  25. </tr>
  26. <!--{/loop}-->
  27. <!--{else}-->
  28. <p> no data for the time being </p>
  29. <!--{/if}-->
  30. </table>
  31. </div>
  32. </div>

publish.php

  1. <?php
  2. if (!defined (' In_discuz '))
  3. {
  4. Exit ("Access denied");
  5. }
  6. if (!$_g[' uid '))
  7. {
  8. ShowMessage (' Sorry, not yet logged in, cannot be published ');
  9. }
  10. if (Submitcheck (' SubmitEdit '))
  11. {
  12. $lbid =dhtmlspecialchars (stripslashes ($_post[' lbid '));
  13. Echo $lbid;
  14. $XMLB =db::fetch_all ("SELECT * from".) Db::table (' jianyanxmlb '). "Where". Db::field (Lbid, $lbid));
  15. echo $xmlb [0][' lbid '];
  16. echo $xmlb [0][' flbid '];
  17. echo $xmlb [0][' Lbname '];
  18. }
  19. if (Submitcheck (' Submit '))
  20. {
  21. $lbid =dhtmlspecialchars (stripslashes ($_post[' lbid '));
  22. $flbid = Cutstr (Dhtmlspecialchars (stripslashes ($_post[' flbid ')), 80, "); Intercept 150 bytes of content
  23. $lbname = Cutstr (Dhtmlspecialchars (stripslashes ($_post[' lbname ')), 150, "); Intercept 150 bytes of content
  24. if (! $lbid)
  25. {
  26. Db::query ("INSERT into".) Db::table (' jianyanxmlb '). " (lbid,flbid,lbname) VALUES (null, ' ". $flbid." ', ' ". $lbname." ') ");
  27. Cpmsg ("Publishing Success", ' action=jianyannav&mod=list ');
  28. }
  29. Else
  30. {
  31. Db::query ("Update". Db::table (' jianyanxmlb '). "Set". Db::field (Flbid, $flbid). ",". Db::field (Lbname, $lbname). "Where". Db::field (Lbid, $lbid));
  32. echo "Update". Db::table (' jianyanxmlb '). "Set". Db::field (Flbid, $flbid). ",". Db::field (Lbname, $lbname). "Where". Db::field (Lbid, $lbid);
  33. Cpmsg ("Editorial success", ' action=jianyannav&mod=list ');
  34. }
  35. }
  36. Include_once Template ("Jianyancp/publish");
  37. ?>

Publish.htm

    1. <div id= "CT" >
    2. <form method= "POST" action= "Admin.php?action=jianyannav&mod=publish" >
    3. <input type= "hidden" name= "Formhash" id= "Formhash" value= "{Formhash}" >
    4. <input type= "hidden" name= "Lbid" id= "Lbid" value= $xmlb [0][' Lbid ']>
    5. <b> parent category Id:</b><input name= "Flbid" id= "Flbid" value= $xmlb [0][' Flbid ']><br>
    6. <b> category name: </b><input name= "Lbname" id= "Lbname" value= $xmlb [0][' Lbname ']><br>
    7. <input type= "Submit" name= "Submit" value= "POST" style= "Float:left" ><br>
    8. </form>
    9. </div>

discuzX2.5 background Operations Custom database tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.