Analysis _php example of thinkphp Mall announcement function development problem

Source: Internet
Author: User
Tags php template codeigniter smarty template zend framework
This paper analyzes the issue of thinkphp Mall announcement function development. Share to everyone for your reference, as follows:

The effect is as follows

1. Set in the head

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

2.ajax Processing JSON data

Get Mall Announcement Function Getnotice () {//Get announcement functions  var res;  $.ajax ({    type: "POST",    URL: "{sh::u (' Store/mall/ajaxgetnotice ', Array (' mid ' = + $mid)}",    DataType: ' JSON ',//set to JSON, it is good to handle the obtained JSON data, 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. Last loaded, the page looks better.

$ (document). Ready (function (e) {//main function  //Get announcement  var action_name = "{sh::action_name}";//page Use thinkphp constant  var JSON = Getnotice ();  if (Action_name = = ' Index ' && json.status = = 1) {//home page and Announcements exist    $ (". Top"). CSS ("Margin-top", "70px");//jquery Set CSS    $ (". Main-sidebar"). CSS ("Top", "70px");    var html = ';    $.each (Json.info, function (i, n) {//n = text content      HTML + = "
  • "+n.content+"
  • " }); $ (". Top-notice"). Show (); $ (' #notice ul '). HTML ("" +html); $ (' #notice '). Unslider (); Carousel });

    4. Get thinkphp processing of SQL statements

    Get Announcement Function Ajaxgetnotice () {    if (is_ajax) {      $this->mid;      Obtain a valid, and end time greater than the current time, or a date equal to 0 of the announcement      $mallNoticeModel = M (' Mall_notice ');      $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 ' = = ' get success '), ' JSON ');      } else {        $this->ajaxreturn (' status ' = ' 2 ', ' info ' = = $notice, ' msg ' = ' "announcement not Present"), ' JSON ');}}    
    $where [' endtime '] = Array (array (' EQ ', 0), array (' GT ', Time ()), ' or ');

    This logical relationship is handled skillfully.

    More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "CodeIgniter Getting Started Tutorial", "CI ( CodeIgniter) Framework Advanced Tutorial, Zend Framework Introduction tutorial, Smarty Template Primer Basic Tutorial and PHP template technology summary.

    It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

  • Related Article

    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.