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.