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.