以实现了页面展示包括动态展示大学图片、大学简介、用户评分、用户关注、用户登录

index控制器:/web/App/Home/Controller/IndexController.class.php

<?php 

/*

* 该部分主要作用是生成大学页面,展示大学信息以及用户评分 关注 留言公共展示,主要: 1.根据url输入参数动态生成大学信息,包括大学图片以及简介等,并将变量输出到对应html模板 2.网站入口页面(首页)index.html关联

*/

namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller {

public function index() {

// $this->show ( 'F:\web\App\Home\Controller\index(控制器)\index方法' );

// 网站首页模板使用,index.html

$this->display ();

}

public function univpage($id) {

//用户登录状态查看 登录为1,未登录为0

session_start ();

$user_id = $_SESSION ["user_id"];

if ($user_id==null) {

$user_state=0;

}

else {

$user_state=1;

}

$this->user_state = $user_state;

// 根据输入id显示学校图片

// 图片路径

$picpath = '/images/' . $id . '.jpg';

// 进行模板变量赋值

$this->picpath = $picpath;

$this->univ_id = $id;

// 实例化模型

$Univ = M ( 'univ_basic_info' );

// 查找相关符合条件字段,使用数组默认为and关系,可添加'_logic'=>'or' 改为或

// 如果getField方法传入多个字段名称的话,默认返回一个关联数组(数组中包含数组),以第一个字段的值为索引

$result = $Univ->where ( array (

'univ_id' => $id

) )->getField ( 'univ_introduce,interest_num,review_num' );

// dump($result);

// 读取数组第一个元素(也就是所有需要元素)

$result = current ( $result );

// dump($result);

$interest_num = $result ["interest_num"];

$univ_introduce = $result ["univ_introduce"];

$review_num = $result ["review_num"];

// echo $univ_introduce;

//用户登录表单控制器方法url

$login_url=U('Userinfo/login_submit');

// 将变量映射到html模板

$this->univ_introduce = $univ_introduce;

$this->interest_num = $interest_num;

$this->review_num = $review_num;

$this->login_url= $login_url;

$this->display ();

}

public function interest() {

// $this->show ( 'F:\web\App\Home\Controller\index(控制器)\index方法' );

$this->display ();

}

public function login() {

// $this->show ( 'F:\web\App\Home\Controller\index(控制器)\index方法' );

$this->display ();

}

}

展示模板:/web/App/Home/View/Index/univpage.html

href="/App/Home/View/Index/review.css">

hello, {$picpath}!

hello, {$univ_introduce}! 关注人数:{$interest_num} 评分人数:{$review_num}

用户状态:{$user_state}

var univ_id = {$univ_id};

/* alert(univ_id); 可以直接在相关的js及ajax调用*/

//用户登录状态参数 js判断此参数弹出登陆界面

var user_state={$user_state};

感觉怎么样?

id="stars2-input" name="b" value="" size="2">

关注

href="/App/Home/View/Index/login_box.css">

style="visibility: hidden; display: none;">

您好,请先登录:
Username:

οnfοcus="select();" />

Password:

name="user_password" οnfοcus="select();" />

控制五星评分的js+css+php

js:/web/App/Home/View/Index/review.js

var TB = function() {

/*

* 该函数为ajax函数  主要是对实现用户点击评分五星,实现对大学评分

* 1.对浏览器进行判断

* 2.用户点击调用review.php脚本

* 3.传递参数

* */

// alert(univ_id);

var T$ = function(id) {

return document.getElementById(id)

}

var T$$ = function(r, t) {

return (r || document).getElementsByTagName(t)

}

var Stars = function(cid, rid, hid, config) {

var lis = T$$(T$(cid), 'li'), curA;

for ( var i = 0, len = lis.length; i < len; i++) {

lis[i]._val = i;

lis[i].onclick = function() {

// 用户点击五角星时生成相应的分数

score = T$$(this, 'a')[0].getAttribute('value');

T$(rid).innerHTML = '' + (T$(hid).value = score)

+ '分 - ' + config.info[this._val];

curA = T$$(T$(cid), 'a')[T$(hid).value / config.step - 1];

// ajax传递变量至php 保存到mysql

var xmlhttp;

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome,

// Opera, Safari

xmlhttp = new XMLHttpRequest();

} else {// code for IE6, IE5

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

// 执行数据库操作php脚本

// 注意此处url变量输入只能够使用?不能使用/

var url = "/App/Home/View/Index/review.php?score=" + score

+ "&univ_id=" + univ_id;

//alert(url);// 检验js传值是否成功

xmlhttp.open("GET", url, true);

xmlhttp.send();

};

lis[i].onmouseout = function() {

curA && (curA.className += config.curcss);

}

lis[i].onmouseover = function() {

curA

&& (curA.className = curA.className.replace(

config.curcss, ''));

}

}

};

return {

Stars : Stars

}

}().Stars('stars2', 'stars2-tips', 'stars2-input', {

'info' : [ '极差', '不怎么好', '一般吧', '不错', '非常好' ],

'curcss' : ' current-rating',

'step' : 20

});

css:/web/App/Home/View/Index/review.css

ul,li {

margin: 0;

padding: 0;

border: 0;

}

.shop-rating {

height: 25px;

overflow: hidden;

zoom: 1;

padding: 2px 0;

position: relative;

z-index: 999;

font: 12px Arial;

color: #000;

line-height: 1.2em;

}

.shop-rating span {

height: 23px;

display: block;

line-height: 23px;

float: left;

}

.shop-rating span.title {

width: 125px;

text-align: right;

margin-right: 5px;

}

.shop-rating ul {

float: left;

}

.shop-rating .result {

margin-left: 20px;

padding-top: 2px;

}

.shop-rating .result span {

color: #ff6d02;

}

.rating-level,.rating-level a {

background: url(/images/o_star.png) no-repeat scroll 1000px 1000px;

}

.rating-level {

background-position: 0px 0px;

width: 120px;

height: 23px;

position: relative;

z-index: 1000;

}

.shop-rating .result em {

color: #f60;

font-family: arial;

font-weight: bold;

}

.rating-level li {

display: inline;

}

.rating-level a {

line-height: 23px;

height: 23px;

position: absolute;

top: 0px;

left: 0px;

text-indent: -999em;

*zoom: 1;

outline: none;

}

.rating-level a.one-star {

width: 20%;

z-index: 6;

}

.rating-level a.two-stars {

width: 40%;

z-index: 5;

}

.rating-level a.three-stars {

width: 60%;

z-index: 4;

}

.rating-level a.four-stars {

width: 80%;

z-index: 3;

}

.rating-level a.five-stars {

width: 100%;

z-index: 2;

}

.rating-level .current-rating,.rating-level a:hover {

background-position: 0 -28px

}

.rating-level a.one-star:hover,.rating-level a.two-stars:hover,.rating-level a.one-star.current-rating,.rating-level a.two-stars.current-rating

{

background-position: 0 -116px;

}

.rating-level .three-stars .current-rating,.rating-level .four-stars .current-rating,.rating-level .five-stars .current-rating

{

background-position: 0 -28px;

}

用户关注写入数据库的原生php脚本(js  ajax如何调用thinkphp方法还未明了)

/web/App/Home/View/Index/review.php

/*

* 该部分主要是用户点击五星评分之后,将操作保存如数据库,主要包括:

* 1.获取js ajax传递过来的univ_id 以及分数score参数

* 2.univ_basic_info中增加用户评分数量

* 3.univ_basic_info计算用户评分平均分数

* */

//获取传递过来的变量分数score和大学id

$score = $_GET ["score"];

echo $score;

$id = $_GET ["univ_id"];

//连接数据库

include_once '/web/cnn.php';

mysql_select_db ( "univinfo", $con );

//更新数据库,并计算平均值

$sql = "UPDATE univ_basic_info SET review_num =review_num+1,average_score=('".$score."'

+(review_num-1)*average_score)/review_num WHERE univ_id ='" . $id . "'";

mysql_query ( $sql );

mysql_close ( $con );

控制用户登录对话框弹出的js+css

js

/web/App/Home/View/Index/login_box.js

var popup_dragging = false;

var popup_target;

var popup_mouseX;

var popup_mouseY;

var popup_mouseposX;

var popup_mouseposY;

var popup_oldfunction;

function popup_display(x) {

var win = window.open();

for ( var i in x)

win.document.write(i + ' = ' + x[i] + '
');

}

function popup_mousedown(e) {

var ie = navigator.appName == "Microsoft Internet Explorer";

if (ie && window.event.button != 1)

return;

if (!ie && e.button != 0)

return;

popup_dragging = true;

popup_target = this['target'];

popup_mouseX = ie ? window.event.clientX : e.clientX;

popup_mouseY = ie ? window.event.clientY : e.clientY;

if (ie)

popup_oldfunction = document.onselectstart;

else

popup_oldfunction = document.onmousedown;

if (ie)

document.onselectstart = new Function("return false;");

else

document.onmousedown = new Function("return false;");

}

function popup_mousemove(e) {

if (!popup_dragging)

return;

var ie = navigator.appName == "Microsoft Internet Explorer";

var element = document.getElementById(popup_target);

var mouseX = ie ? window.event.clientX : e.clientX;

var mouseY = ie ? window.event.clientY : e.clientY;

element.style.left = (element.offsetLeft + mouseX - popup_mouseX) + 'px';

element.style.top = (element.offsetTop + mouseY - popup_mouseY) + 'px';

popup_mouseX = ie ? window.event.clientX : e.clientX;

popup_mouseY = ie ? window.event.clientY : e.clientY;

}

function popup_mouseup(e) {

if (!popup_dragging)

return;

popup_dragging = false;

var ie = navigator.appName == "Microsoft Internet Explorer";

var element = document.getElementById(popup_target);

if (ie)

document.onselectstart = popup_oldfunction;

else

document.onmousedown = popup_oldfunction;

}

function popup_exit(e) {

var ie = navigator.appName == "Microsoft Internet Explorer";

var element = document.getElementById(popup_target);

popup_mouseup(e);

element.style.visibility = 'hidden';

element.style.display = 'none';

}

function popup_show() {

//alert('wewe');

//用过用户登录状态参数为0,表示没有登录则弹出登录窗口

if (user_state == 0) {

element = document.getElementById('popup');

drag_element = document.getElementById('popup_drag');

exit_element = document.getElementById('popup_exit');

element.style.position = "absolute";

element.style.visibility = "visible";

element.style.display = "block";

element.style.left = (document.documentElement.scrollLeft

+ popup_mouseposX - 10)

+ 'px';

element.style.top = (document.documentElement.scrollTop

+ popup_mouseposY - 10)

+ 'px';

drag_element['target'] = 'popup';

drag_element.onmousedown = popup_mousedown;

exit_element.onclick = popup_exit;

}

}

function popup_mousepos(e) {

var ie = navigator.appName == "Microsoft Internet Explorer";

popup_mouseposX = ie ? window.event.clientX : e.clientX;

popup_mouseposY = ie ? window.event.clientY : e.clientY;

}

if (navigator.appName == "Microsoft Internet Explorer")

document.attachEvent('onmousedown', popup_mousepos);

else

document.addEventListener('mousedown', popup_mousepos, false);

if (navigator.appName == "Microsoft Internet Explorer")

document.attachEvent('onmousemove', popup_mousemove);

else

document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")

document.attachEvent('onmouseup', popup_mouseup);

else

document.addEventListener('mouseup', popup_mouseup, false);

css:

/web/App/Home/View/Index/login_box.css

@CHARSET "UTF-8";

div.sample_popup {

z-index: +1;

}

div.menu_form_header {

cursor: move

}

div.sample_popup div.menu_form_header {

border: 1px solid black;

border-bottom: 0px;

cursor: default;

width: 200px;

height: 20px;

line-height: 19px;

vertical-align: middle;

background: url('jscss/demoimg/200904/20title.png')

no-repeat;

text-decoration: none;

font-family: "Times New Roman", Serif;

font-weight: 900;

font-size: 13px;

color: #206040;

}

div.sample_popup div.menu_form_body {

border: 1px solid black;

width: 200px;

background: url('jscss/demoimg/200904/logbg.png')

no-repeat left bottom;

}

div.sample_popup img.menu_form_exit {

float: right;

margin: 4px 5px 0px 0px;

cursor: pointer;

}

div.sample_popup table {

border-collapse: collapse;

width: 100%;

}

div.sample_popup th {

width: 1%;

padding: 0px 5px 1px 0px;

text-align: left;

font-family: "Times New Roman", Serif;

font-weight: 900;

font-size: 13px;

color: #004060;

}

div.sample_popup td {

width: 99%;

padding: 0px 0px 1px 0px;

}

div.sample_popup form {

margin: 0px;

padding: 8px 10px 10px 10px;

}

div.sample_popup input.field {

border: 1px solid #808080;

width: 95%;

font-family: Arial, Sans-Serif;

font-size: 12px;

}

div.sample_popup input.btn {

margin-top: 2px;

border: 1px solid #808080;

background-color: #DDFFDD;

font-family: Verdana, Sans-Serif;

font-size: 11px;

}

a {

color: #FF0000;

text-decoration: none;

}

用户点击关注js+php

js /web/App/Home/View/Index/interest.js

function loadXMLDoc()

/*

* 该函数为ajax函数  主要是对实现用户点击关注按钮,实现对大学关注

* 1.对浏览器进行判断

* 2.用户点击调用interest.php脚本

* 3.传递参数

* 4.判断用户是否登录,如果没有登录则弹出登录界面

* */

{

if (user_state==0)

{

// alert("请先登录");

//调用login_box.js当中的方法 统一页面直接调用

popup_show();

}

var xmlhttp;

if (window.XMLHttpRequest)

{// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

}

else

{// code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function()

{

if (xmlhttp.readyState==4 && xmlhttp.status==200)

{

document.getElementById("interest_state").innerHTML=xmlhttp.responseText;

}

}

//xmlhttp.open("GET","/App/Home/View/Index/js.txt",true);

//var url = "/App/Home/View/Index/interest.php?univ_id=" + univ_id;

var url = "/App/Home/View/Index/interest.php?univ_id=" + univ_id;

xmlhttp.open("GET",url,true);

xmlhttp.send();

}

用户关注操作写入数据库php

/web/App/Home/View/Index/interest.php

/*

* 该部分主要是用户点击页面关注按钮之后,将操作保存如数据库,主要包括: 1.获取js ajax interest.js文件传递过来的大学id参数 2.从session当中判断用户是否登录 3.从seesion当中获取登录用户的id 4.向univ_user_interest添加关注对应数据 5.修改univ_basic_info中大学用户关注数目

*/

// session获取参数

session_start ();

$user_id = $_SESSION ["user_id"];

$univ_id = $_GET ["univ_id"];

// 连接数据库

include_once '/web/cnn.php';

$sql = "SELECT count(*) as count FROM univ_user_interest WHERE univ_id ='" . $univ_id . "'and user_id='" . $user_id . "'";

$result = mysql_query ( $sql );

$row = mysql_fetch_array ( $result );

$ifexist = $row ['count'];

// echo $ifexist;

// 判断用户是否已经关注,如果没有则进行关注

if ($ifexist != 0) {

echo "您已经关注";

} else {

// 添加判断语句 判断where(user_id=$user_id, univ_id=$univ_id)是否已

// 经存在 不存在将用户关注信息添加到数据库

$sql = "INSERT INTO univ_user_interest (user_id, univ_id)

VALUES ('" . $user_id . "', '" . $univ_id . "')";

echo "关注成功";

mysql_query ( $sql );

// 数据表univ_basic_info 当中的关注数量interest_num增加1

$sql = "UPDATE univ_basic_info SET interest_num =interest_num+1 WHERE univ_id ='" . $univ_id . "'";

mysql_query ( $sql );

}

// 断开数据库连接

mysql_close ( $con );

php入门案例,thinkphp3.2.1入门之--简单案例实现相关推荐

  1. 开课吧python视频百度云-廖雪峰老师官方人工智能教程,13个案例带你全面入门!...

    现在互联网上广为流传的[18届互联网校招薪酬表],震惊了还在敲代码的小编我,给你们看看这张高薪表 可以看到上图50%以上的高薪都是AI相关的岗位,不管是具备了算法还是数据挖掘分析的能力,都是BAT以及 ...

  2. 【Python基础】Matplotlib 实操干货,38个案例带你从入门到进阶!

    译文出品:Python数据之道 原文作者:Rizky Maulana Nurhidayat 翻译:Lemon Matplotlib 实操干货, 38个案例带你从入门到进阶! 「Python数据之道」注 ...

  3. python爬虫教程-Python教父|廖雪峰老师官方爬虫教程,13个案例带你全面入门!

    原标题:Python教父|廖雪峰老师官方爬虫教程,13个案例带你全面入门! Python简直就是万能的,你用Python都做过哪些事? 用网页看各大网站的VIP视频,用python下载? 用Pytho ...

  4. Python数据分析入门笔记10——简单案例练习(学生信息分析)

    系列文章目录 Python数据分析入门笔记1--学习前的准备 Python数据分析入门笔记2--pandas数据读取 Python数据分析入门笔记3--数据预处理之缺失值 Python数据分析入门笔记 ...

  5. [Python从零到壹] 四.网络爬虫之入门基础及正则表达式抓取博客案例

    欢迎大家来到"Python从零到壹",在这里我将分享约200篇Python系列文章,带大家一起去学习和玩耍,看看Python这个有趣的世界.所有文章都将结合案例.代码和作者的经验讲 ...

  6. Three 之 three.js (webgl)基础 第二个入门案例之汽车模型加载和简单模型展示

    Three 之 three.js (webgl)基础 第二个入门案例之汽车模型加载和简单模型展示 目录 ​Three 之 three.js (webgl)基础 第二个入门案例之汽车模型加载和简单模型展 ...

  7. Unicode入门与剖析——从一个越南文的案例说起

    Unicode入门与剖析--从一个越南文的案例说起 写在前面     和大多数人一样,我本来对Unicode也是一知半解.由于从微软的VS2003开始(说起来竟然是8年以前了),Unicode已经是一 ...

  8. c#使用正则表达式获取TR中的多个TD_[Python从零到壹] 四.网络爬虫之入门基础及正则表达式抓取博客案例...

    首先祝大家中秋节和国庆节快乐,欢迎大家来到"Python从零到壹",在这里我将分享约200篇Python系列文章,带大家一起去学习和玩耍,看看Python这个有趣的世界.所有文章都 ...

  9. 基于python的人工智能的案例-廖雪峰大牛13个案例带你全面入门人工智能!

    现在互联网上广为流传的[18届互联网校招薪酬表],震惊了还在敲代码的小编我,给你们看看这张高薪表 可以看到上图50%以上的高薪都是AI相关的岗位,不管是具备了算法还是数据挖掘分析的能力,都是BAT以及 ...

  10. 1.4_21 Axure RP 9 for mac 高保真原型图 - 案例20【中继器 - 入门1】中继器原理Repeater Table

    相关链接 目录 Axure中文学习网 AxureShop AxureShop-QA 案例目标  1. 了解 中继器 是什么  2. 了解 中继器 的使用场景  3. 会使用 中继器 展示数据  4. ...

最新文章

  1. hdu4277 DFS+SET
  2. 【Android 逆向】Android 逆向通用工具开发 ( Windows 平台运行的控制台应用程序类型 | 编译 Windows 平台运行的 Android 逆向程序 )
  3. Java线程详解(4)-线程状态的转换
  4. 银行错误将10万打给自己,客户有责任退还,银行难道没责任吗?
  5. 使用 Caddy 替代 Nginx,全站升级 https,配置更加简单
  6. 深度模型不work?这有一份超全的Debug检查清单
  7. 聚焦惠普质量问题是否带来行业变化?
  8. Android文字的复制和粘贴
  9. Vue 当中的计算属性computed
  10. 一步一步教你 https 抓包
  11. 小米网站短信验证码接口的轰炸防护
  12. 计算机系统应用属于ei,2018年度中心成员发表论文清单(SCI、EI收录)
  13. Retrofit实现App更新
  14. java jca_Java加密体系结构(JCA)参考指南
  15. RFID读写---RFID读卡
  16. axure9总是崩_axure老是崩怎么办
  17. 对于程序员来说养成规范的打字真的很重要
  18. texstudio暗色主题2.0
  19. 深度学习推荐系统中各类流行的Embedding方法(下)
  20. clickhouse-jdbc 源码学习

热门文章

  1. 《敏捷迭代开发:管理者指南》—第2章2.3节时间箱迭代开发
  2. MYSQL服务器my.cnf配置文档详解
  3. python(12)给文件读写上锁
  4. java.io.Serializab接口
  5. JUC锁框架——重入锁ReentrantLock
  6. Springboot监控之二:Spring Boot Admin对Springboot服务进行监控
  7. Ovum 最新市场报告称数据中心持续改变光网络市场
  8. Junit +cucumber 运行报错 initiallizationError
  9. 2602 最短路径问题
  10. Eclipse修改XML默认打开方式