ThinkPHP marketplace announcement function development problem analysis _ php instance

Source: Internet
Author: User
This article mainly introduces thinkPHP Mall announcement function development issues, and analyzes the ajax interaction and database operation related skills involved in the mall announcement function based on thinkPHP in the form of examples, if you need it, you can refer to the example below to analyze thinkPHP Mall announcement function development issues. We will share this with you for your reference. The details are as follows:

The effect is as follows:

1. set it to the header

position: fixed;z-index: 999;top: 0;opacity:1;

2. ajax processing json data

// Obtain the mall announcement function getNotice () {// Obtain the announcement function var res; $. ajax ({type: "POST", url: "{sh: U ('store/Mall/ajaxGetNotice ', array ('mid' => $ mid ))}", dataType: 'json', // after it is set to json, it can well process the obtained json data, json. status async: false, success: function (json) {res = json ;}}); return res ;}

After dataType: 'json' is set, json data can be processed directly in json. mode.

3. finally, load the file to make the page look better.

$ (Document ). ready (function (e) {// Main function // Obtain the announcement var action_name = "{sh: ACTION_NAME}"; // use the thinkphp Constant var json = getNotice () on the page (); if (action_name = 'index' & json. status = 1) {// The homepage with the announcement $ (". top ").css (" margin-top "," 70px "); // Set css $ (". main-sidebar ").css (" top "," 70px "); var html =''; $. each (json.info, function (I, n) {// n is the text content html + ="
  • "+ N. content +"
  • "}); $ (". Top-notice "). show (); $ ('# notice ul'{.html ("" + html); $ (' # notice '). unslider (); // carousel }});

    4. obtain thinkphp processing of SQL statements

    // Obtain the announcement function ajaxGetNotice () {if (IS_AJAX) {$ this-> mid; // obtain valid and end time greater than the current time, or an announcement with a date equal to 0 $ mallNoticeModel = M ('Mall _ notice '); $ where ['Mall _ id'] = $ this-> mid; $ where ['status'] = 1; $ where ['endtime'] = array ('EQ ', 0), array ('GT', time ()), 'or'); // SELECT * from sh_mall_notice where mall_id = 9 and status = 1 and (endtime = 0 or endtime> 1458354366 ); $ notice = $ mallNoticeModel-> where ($ where)-> Order ('sort desc')-> select (); if (! Empty ($ notice) {$ this-> ajaxReturn (array ('status' => '1', 'info' => $ notice, 'MSG '=> "obtained successfully"), 'json');} else {$ this-> ajaxReturn (array ('status' => '2 ', 'info' => $ notice, 'MSG '=> "announcement does not exist"), 'json ');}}}

    $where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;

    It cleverly handles this logical relationship.

    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.