thinkphp Mall Bulletin Function Development problem Analysis _php Example

Source: Internet
Author: User
Tags current time json php template codeigniter zend framework

This article analyzes the Thinkphp Mall bulletin function development problem. Share to everyone for your reference, specific as follows:

The effect is as follows

1. Fixed in the head

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

2.ajax Processing JSON data

Get Mall Bulletin
function Getnotice () {//Get bulletin functions
  var res;
  $.ajax ({
    type: "POST",
    URL: "{sh::u (' Store/mall/ajaxgetnotice ', Array (' mid ' => $mid)}",
    DataType: ' JSON ', when set to JSON, will be able to handle the captured JSON data very well, Json.status
    async:false,
    success:function (JSON) {
      res = JSON;
    }
  });
  return res;
}

After setting datatype: ' JSON ', the JSON data can be processed directly via JSON.

3. Finally load, the page looks better.

$ (document). Ready (function (e) {//main function
  //Get bulletin
  var action_name = ' {sh::action_name} ';//page uses thinkphp constant
  var JSON = Getnotice ();
  if (Action_name = = ' Index ' && json.status = = 1) {//The first page and the announcement exists
    $ (". Top"). CSS ("Margin-top", "70px");//jquery Set CSS
    $ (". Main-sidebar"). CSS ("Top", "70px");
    var html = ';
    $.each (Json.info, function (i, n) {//N for text content
      HTML = "<li><strong>" +n.content+ "</strong></li > "
    });
    $ (". Top-notice"). Show ();
    $ (' #notice ul '). HTML ("" +html);
    $ (' #notice '). Unslider (); Carousel
  }
});

4. Get thinkphp processing of SQL statements

Gets the post
function Ajaxgetnotice () {
    if (is_ajax) {
      $this->mid;
      The announcement
      $mallNoticeModel = M (' Mall_notice ') that is valid and whose end time is greater than the current time, or the date equals 0;
      $where [' mall_id '] = $this->mid;
      $where [' status '] = 1;
      $where [' endtime '] = Array (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 (' status ' => ' 1 ', ' info ' => $notice, ' msg ' => ' obtain success '), ' JSON ');
      } else {
        $this->ajaxreturn array (' status ' => ' 2 ', ' info ' => $notice, ' msg ' => ' Bulletin does not exist '), ' JSON ');
      }
}

$where [' endtime '] = Array (array (' EQ ', 0), array (' GT ', Time ()), ' or ');

Cleverly dealt with this kind of logical relationship.

More interested readers of thinkphp related content can view the website topic: "thinkphp Introductory Course", "thinkphp template Operation Skill Summary", "thinkphp Common Method Summary", "The CodeIgniter Introductory Course", "CI ( CodeIgniter) Framework Advanced tutorials, introductory tutorials for the Zend framework Framework, Smarty Templates Primer tutorial, and PHP template technology summary.

I hope this article will help you with the PHP program design based on thinkphp framework.

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.