PHP+jQuery+Ajax+Mysql实现发表心情功能
我们在浏览网站文章或帖子后,需要表达自己浏览后的心情感受,在很多网站都提供了给用户发表心情的功能,通过这个功能可以直观统计分析文章或帖子的浏览者的心情感受数据。在本文中,您将了解到,如何实现通过点击心情图标,即刻发表自己的心情。
下载 http://bbs.php100.com/read-htm-tid-391083-ds-1.html
本文通过实例讲解使用PHP+jQuery+Ajax+Mysql相结合,实现了用户发表心情的功能,操作简单,实用性强,是一篇将WEB知识进行综合应用的文章,因此读者需要具备PHP、Mysql、jQuery以及ajax相关知识。
本示例的大致原理和流程是这样的:主页面index.html通过ajax获取心情图标及柱状图相关数据,当用户点击其中的一个心情图标时,向后台php发送请求,PHP验证用户cookie防止重复提交,然后将mysql中对应的数据心情字段内容加1,成功后返回前端页面,告诉index.html发表成功,并调整柱状图和统计数据。
HTML
先看HTML,我们在index.html中放置一个#msg,用来显示操作结果信息,#mood是操作主区域,其中ul通过javascript异步加载心情图标、说明、柱状图以及统计信息。
<code class="html" style="margin: 0px; padding: 0px; "> <span class="html__tag_start" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; "><div> <span class="html__attr_name" style="margin: 0px; padding: 0px; color: green; ">id</span>=<span class="html__attr_value" style="margin: 0px; padding: 0px; color: maroon; ">"msg"</span><span class="html__tag_start" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">></span><span class="html__tag_end" style="margin: 0px; padding: 0px; color: navy; "></span> </div></span> <span class="html__tag_start" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; "><div> id=mood<span class="html__tag_start" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">></span> <span class="html__tag_start" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; "><ul> <span class="html__tag_start" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">></span><span class="html__tag_end" style="margin: 0px; padding: 0px; color: navy; "></span> </ul></span> <span class="html__tag_end" style="margin: 0px; padding: 0px; color: navy; "></span> </div></span> </code>
PHP
首先我们在config.php配置文件中,配置数据库连接信息,以及示例相关参数。
<code class="php" style="margin: 0px; padding: 0px; "> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">host</span>=<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"localhost"</span>; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">db_user</span>=<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"root"</span>; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">db_pass</span>=<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">""</span>; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">db_name</span>=<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"demo"</span>; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">link</span>=mysql_connect(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">host</span>,<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">db_user</span>,<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">db_pass</span>); mysql_select_db(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">db_name</span>,<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">link</span>); mysql_query(<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"SET names UTF8"</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情说明,用半角逗号隔开</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodname</span>=<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'震惊,不解,愤怒,杯具,无聊,高兴,支持,超赞'</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情图标文件,用半角逗号隔开(template/images/目录)</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodpic</span>=<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'a1.gif,a2.gif,a3.gif,a4.gif,a5.gif,a6.gif,a7.gif,a8.gif'</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//统计心情柱图标最大高度</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodpicheight</span>=<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">80</span>; </code>
接下来,我们在mood.php中准备分两部分,通过接收action参数,分为第一部分:发表心情,第二部分:获取心情相关信息。
<code class="php" style="margin: 0px; padding: 0px; "> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">include_once</span>(<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"config.php"</span>); <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">action</span> = <span class="php__global" style="margin: 0px; padding: 0px; color: red; ">$_GET</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'action'</span>]; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">action</span>==<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'send'</span>){ <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//发表心情</span> ... }<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">else</span>{ <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//获取心情</span> ... } </code>
Part1:发表心情。
用户从前端通过post提交发表心情的参数,包括文章id,心情id。先验证文章是否存在,然后再验证用户是否已经对这篇文章发表过心情了,接着操作数据库,将对应的心情字段值+1,并计算出当前心情对应的柱状图的高度,返回给前端js接收。
<code class="php" style="margin: 0px; padding: 0px; "> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span> = (int)<span class="php__global" style="margin: 0px; padding: 0px; color: red; ">$_POST</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'id'</span>]; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//文章或帖子id</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mid</span> = (int)<span class="php__global" style="margin: 0px; padding: 0px; color: red; ">$_POST</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'moodid'</span>]; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情id(配置文件中提供8种心情)</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(!<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mid</span> !<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>){ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">echo</span> <span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"此链接不存在"</span>;<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">exit</span>; } <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">havemood</span> = chk_mood(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//验证cookie</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">havemood</span>==<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">1</span>){ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">echo</span> <span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"您已经表达过心情了,保持平常心有益身心健康!"</span>;<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">exit</span>; } <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">field</span> = <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood'</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mid</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//数据表中的心情字段,分别用mood0,mood1,mood2...表示不同的心情字段</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">query</span> = mysql_query(<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"update mood set "</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">field</span>.<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"="</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">field</span>.<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"+1 where id="</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//对应的心情字段值+1</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">query</span>){ setcookie(<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"mood"</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>, <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mid</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>, time()+<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">300</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//设置cookie,为了测试我们设置cookie过期时间为300s</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">query2</span> = mysql_query(<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"select * from mood where id=$id"</span>); <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span> = mysql_fetch_array(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">query2</span>);<span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//获取该文章的心情数据</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">total</span> = <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood0'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood1'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood2'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood3'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood4'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood5'</span>]+ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood6'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood7'</span>]; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">height</span> = round((<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">field</span>]/<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">total</span>)*<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodpicheight</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//得到总量,并计算当前对应心情的柱状图的高度</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">echo</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">height</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//返回当前心情柱状的高度</span> }<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">else</span>{ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">echo</span> -<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">1</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//数据出错</span> } </code>
验证用户是否已发表过心情,我们通过函数chk_mood()来判断用户对应的cookie是否存在。
<code class="php" style="margin: 0px; padding: 0px; "> <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//验证是否提交过</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">function</span> chk_mood(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>){ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">cookie</span> = <span class="php__global" style="margin: 0px; padding: 0px; color: red; ">$_COOKIE</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood'</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span>]; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">cookie</span>){ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">doit</span> = <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">1</span>; }<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">else</span>{ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">doit</span> = <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">0</span>; } <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">return</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">doit</span>; } </code>
Part2:获取心情
通过获取数据表中文章或帖子id对应的心情数据,得到每种心情对应的值(可以理解为发表心情的次数),并计算其柱状图高度,将每种心情对应的值、名称、图标、高度信息构造成数组,最终以JSON格式数据返回给前端。
<code class="php" style="margin: 0px; padding: 0px; "> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mname</span> = explode(<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">','</span>,<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodname</span>);<span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情说明</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">num</span> = count(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mname</span>); <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mpic</span> = explode(<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">','</span>,<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodpic</span>);<span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情图标</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">id</span> = (int)<span class="php__global" style="margin: 0px; padding: 0px; color: red; ">$_GET</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'id'</span>]; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//文章或帖子id</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">query</span> = mysql_query(<span class="php__string2" style="margin: 0px; padding: 0px; color: fuchsia; ">"select * from mood where id=$id"</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//查询对应的心情数据</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span> = mysql_fetch_array(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">query</span>); <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>){ <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//得到发表心情的总量</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">total</span> = <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood0'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood1'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood2'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood3'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood4'</span>]+ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood5'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood6'</span>]+<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood7'</span>]; <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">for</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>=<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">0</span>;<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>$<span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">num</span>;<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>++){ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">field</span> = <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood'</span>.<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//字段名</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">m_val</span> = intval(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">rs</span>[<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">field</span>]); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情对应的值(次数)</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">height</span> = <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">0</span>; <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//柱图高度</span> <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">total</span> && <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">m_val</span>){ <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">height</span>=round((<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">m_val</span>/<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">total</span>)*<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">moodpicheight</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//计算高度</span> } <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">arr</span>[] = <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">array</span>( <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mid'</span> => <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>, <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//对应心情id</span> <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood_name'</span> => <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mname</span>[<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>], <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//心情名称</span> <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood_pic'</span> => <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">mpic</span>[<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">i</span>], <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//图标</span> <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'mood_val'</span> => <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">m_val</span>, <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//次数</span> <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'height'</span> => <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">height</span> <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//柱状图高度</span> ); } <span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">echo</span> json_encode(<span class="php__keyword" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">$</span><span class="php__variable" style="margin: 0px; padding: 0px; color: rgb(64, 64, 194); ">arr</span>); <span class="php__com" style="margin: 0px; padding: 0px; color: green; ">//返回JSON数据</span> } </code>
jQuery
我们使用强大的jQuery来完成本例中所有ajax的交互动作,因此在index.html中要先载入jquery.js库,目前1.8版本已经发布了哦,可以到官网http://jquery.com/下载。
接着我们向mood.php发送Ajax请求,获取心情列表信息,并展示在index.html页面中。
<code class="js" style="margin: 0px; padding: 0px; "> $(<span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">function</span>()<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> $.ajax(<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> type: <span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'GET'</span>, <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//通过get方式发送请求</span> url: <span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'mood.php'</span>, <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//目标地址</span> cache: false, <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//不缓存数据,注意文明发表心情的数据是实时的,需将cache设置为false,默认是true</span> data: <span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'id=1'</span>, <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//参数,对应文章或帖子的id,本例中固定为1,实际应用中是获取当前文章或帖子的id</span> dataType: <span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'json'</span>, <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//数据类型为json</span> error: <span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">function</span>()<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> alert(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'出错了!'</span>); <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>, success: <span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">function</span>(json)<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//请求成功后</span> <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(json)<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> $.each(json,<span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">function</span>(index,array)<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//遍历json数据列</span> <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">var</span> str = <span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"<li> <span>"</span>+array[<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'mood_val'</span>]+"</li></span><div style="\<span" class="js__string">"height:"+array[<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'height'</span>]+"px;\"></div> <div rel="\<span" class="js__string" style="margin: 0px; padding: 0px; color: teal; ">""+array[<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'mid'</span>]+<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"\"><img alt="PHP+jQuery+Ajax+Mysql实现发表心情功能" >+array[<span class="js__string" style="max-width:90%">'mood_pic'</span>]+"\"> <br>"+array['mood_name']+"</span> </div>"; $(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"#mood ul"</span>).append(str); <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//将数据加入到#mood ul列表中</span> <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>); <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span> <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span> <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>); ... <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>); </code>
这样,我们在访问index.html后,页面会载入心情列表,当然要想看到最终排列效果,还需要CSS,本文不讲解相关CSS,请下载源码或查看demo了解。
接下来,我们有个交互动作,当点击对应的心情图标时,图标被标识为已发表,柱状图高度发生变化,并且上面的数字会+1,表示发表成功,如果继续点击心情图标,会提示已经发表过不能重复提交。请看代码:
<code class="js" style="margin: 0px; padding: 0px; "> $(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">".face"</span>).live(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">'click'</span>,<span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">function</span>()<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//侦听点击事件</span> <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">var</span> face = $(<span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">this</span>); <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">var</span> mid = face.attr(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"rel"</span>); <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//对应的心情id</span> <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">var</span> value = face.parent().find(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"span"</span>).html(); <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">var</span> val = <span class="js__function" style="margin: 0px; padding: 0px; color: olive; ">parseInt</span>(value)+<span class="js__num" style="margin: 0px; padding: 0px; color: red; ">1</span>; <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//数字加1</span> <span class="js__sl_comment" style="margin: 0px; padding: 0px; color: green; ">//提交post请求</span> $.post(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"mood.php?action=send"</span>,<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span>moodid:mid,id:<span class="js__num" style="margin: 0px; padding: 0px; color: red; ">1</span><span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>,<span class="js__operator" style="margin: 0px; padding: 0px; color: rgb(65, 105, 225); font-weight: bold; ">function</span>(data)<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> <span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">if</span>(data><span class="js__num" style="margin: 0px; padding: 0px; color: red; ">0</span>)<span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> face.prev().css(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"height"</span>,data+<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"px"</span>); face.parent().find(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"span"</span>).html(val); face.find(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"img"</span>).addClass(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"selected"</span>); $(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"#msg"</span>).show().html(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"操作成功"</span>).fadeOut(<span class="js__num" style="margin: 0px; padding: 0px; color: red; ">2000</span>); <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span><span class="js__statement" style="margin: 0px; padding: 0px; color: navy; font-weight: bold; ">else</span><span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">{</span> $(<span class="js__string" style="margin: 0px; padding: 0px; color: teal; ">"#msg"</span>).show().html(data).fadeOut(<span class="js__num" style="margin: 0px; padding: 0px; color: red; ">2000</span>); <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span> <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>); <span class="js__brace" style="margin: 0px; padding: 0px; color: red; font-weight: bold; ">}</span>); </code>
没看明白的童鞋可以下载源码仔细研究,点击文章开头的Download按钮即可下载,最后附上本例所需的mysql数据表结构,谢谢您的关注。
<code class="php" style="margin: 0px; padding: 0px; "> CREATE TABLE IF NOT EXISTS `mood` ( `id` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span>, `mood0` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood1` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood2` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood3` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood4` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood5` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood6` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, `mood7` int(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">11</span>) NOT <span class="php__value" style="margin: 0px; padding: 0px; color: gray; font-weight: bold; ">NULL</span> DEFAULT <span class="php__string1" style="margin: 0px; padding: 0px; color: purple; ">'0'</span>, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `mood` (`id`, `mood0`, `mood1`, `mood2`, `mood3`, `mood4`, `mood5`, `mood6`, `mood7`) VALUES(<span class="php__number" style="margin: 0px; padding: 0px; color: red; ">1</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">8</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">6</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">20</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">16</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">6</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">9</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">15</span>, <span class="php__number" style="margin: 0px; padding: 0px; color: red; ">21</span>); </code>

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











로그인 화면에 "귀하의 조직에서 PIN 변경을 요구합니다"라는 메시지가 나타납니다. 이는 개인 장치를 제어할 수 있는 조직 기반 계정 설정을 사용하는 컴퓨터에서 PIN 만료 제한에 도달한 경우 발생합니다. 그러나 개인 계정을 사용하여 Windows를 설정하는 경우 이상적으로는 오류 메시지가 나타나지 않습니다. 항상 그런 것은 아니지만. 오류가 발생한 대부분의 사용자는 개인 계정을 사용하여 신고합니다. 조직에서 Windows 11에서 PIN을 변경하도록 요청하는 이유는 무엇입니까? 귀하의 계정이 조직과 연결되어 있을 수 있으므로 이를 확인하는 것이 기본 접근 방식입니다. 도메인 관리자에게 문의하면 도움이 될 수 있습니다! 또한 잘못 구성된 로컬 정책 설정이나 잘못된 레지스트리 키로 인해 오류가 발생할 수 있습니다. 지금 바로

Windows 11은 신선하고 우아한 디자인을 전면에 내세웠습니다. 현대적인 인터페이스를 통해 창 테두리와 같은 미세한 세부 사항을 개인화하고 변경할 수 있습니다. 이 가이드에서는 Windows 운영 체제에서 자신의 스타일을 반영하는 환경을 만드는 데 도움이 되는 단계별 지침을 설명합니다. 창 테두리 설정을 변경하는 방법은 무엇입니까? +를 눌러 설정 앱을 엽니다. Windows개인 설정으로 이동하여 색상 설정을 클릭합니다. 색상 변경 창 테두리 설정 창 11" Width="643" Height="500" > 제목 표시줄 및 창 테두리에 강조 색상 표시 옵션을 찾아 옆에 있는 스위치를 토글합니다. 시작 메뉴 및 작업 표시줄에 강조 색상을 표시하려면 시작 메뉴와 작업 표시줄에 테마 색상을 표시하려면 시작 메뉴와 작업 표시줄에 테마 표시를 켭니다.

AppleID를 사용하여 iTunesStore에 로그인하면 "이 AppleID는 iTunesStore에서 사용되지 않았습니다"라는 오류가 화면에 표시될 수 있습니다. 걱정할 오류 메시지는 없습니다. 다음 솔루션 세트에 따라 문제를 해결할 수 있습니다. 수정 1 – 배송 주소 변경 iTunes Store에 이 메시지가 나타나는 주된 이유는 AppleID 프로필에 올바른 주소가 없기 때문입니다. 1단계 – 먼저 iPhone에서 iPhone 설정을 엽니다. 2단계 – AppleID는 다른 모든 설정보다 우선해야 합니다. 그러니 열어보세요. 3단계 – 거기에서 “결제 및 배송” 옵션을 엽니다. 4단계 – Face ID를 사용하여 액세스 권한을 확인하세요. 단계

기본적으로 Windows 11의 제목 표시줄 색상은 선택한 어두운/밝은 테마에 따라 다릅니다. 그러나 원하는 색상으로 변경할 수 있습니다. 이 가이드에서는 이를 변경하고 데스크톱 환경을 개인화하여 시각적으로 매력적으로 만드는 세 가지 방법에 대한 단계별 지침을 논의합니다. 활성 창과 비활성 창의 제목 표시줄 색상을 변경할 수 있습니까? 예, 설정 앱을 사용하여 활성 창의 제목 표시줄 색상을 변경하거나 레지스트리 편집기를 사용하여 비활성 창의 제목 표시줄 색상을 변경할 수 있습니다. 이러한 단계를 알아보려면 다음 섹션으로 이동하세요. Windows 11에서 제목 표시줄 색상을 변경하는 방법은 무엇입니까? 1. 설정 앱을 사용하여 +를 눌러 설정 창을 엽니다. Windows"개인 설정"으로 이동한 다음

Windows 11/10의 이벤트 뷰어에서 이벤트 ID 55, 50, 140, 98이 발견되거나, 디스크 파일 시스템 구조가 손상되어 사용할 수 없다는 오류가 발생하는 경우, 아래 안내에 따라 문제를 해결하시기 바랍니다. 이벤트 55, 디스크의 파일 시스템 구조가 손상되어 사용할 수 없음은 무엇을 의미합니까? 세션 55에서 Ntfs 디스크의 파일 시스템 구조가 손상되어 사용할 수 없습니다. 볼륨에서 chkMSK 유틸리티를 실행하십시오. NTFS가 트랜잭션 로그에 데이터를 쓸 수 없으면 이벤트 ID 55의 오류가 트리거되어 NTFS가 트랜잭션 데이터를 쓸 수 없는 작업을 완료하지 못하게 됩니다. 이 오류는 일반적으로 디스크에 불량 섹터가 있거나 파일 시스템의 디스크 하위 시스템이 부적절하여 파일 시스템이 손상된 경우에 발생합니다.

Windows Installer 페이지에 "OOBELANGUAGE" 문과 함께 "문제가 발생했습니다."가 표시됩니까? 이러한 오류로 인해 Windows 설치가 중단되는 경우가 있습니다. OOBE는 즉시 사용 가능한 경험을 의미합니다. 오류 메시지에서 알 수 있듯이 이는 OOBE 언어 선택과 관련된 문제입니다. 걱정할 필요가 없습니다. OOBE 화면 자체에서 레지스트리를 편집하면 이 문제를 해결할 수 있습니다. 빠른 수정 – 1. OOBE 앱 하단에 있는 “다시 시도” 버튼을 클릭하세요. 그러면 더 이상의 문제 없이 프로세스가 계속됩니다. 2. 전원 버튼을 사용하여 시스템을 강제 종료합니다. 시스템이 다시 시작된 후 OOBE가 계속되어야 합니다. 3. 인터넷에서 시스템 연결을 끊습니다. 오프라인 모드에서 OOBE의 모든 측면을 완료하세요.

작업 표시줄 축소판은 재미있을 수도 있지만 주의를 산만하게 하거나 짜증나게 할 수도 있습니다. 이 영역 위로 얼마나 자주 마우스를 가져가는지 고려하면 실수로 중요한 창을 몇 번 닫았을 수도 있습니다. 또 다른 단점은 더 많은 시스템 리소스를 사용한다는 것입니다. 따라서 리소스 효율성을 높일 수 있는 방법을 찾고 있다면 비활성화하는 방법을 알려드리겠습니다. 그러나 하드웨어 사양이 이를 처리할 수 있고 미리 보기가 마음에 들면 활성화할 수 있습니다. Windows 11에서 작업 표시줄 축소판 미리 보기를 활성화하는 방법은 무엇입니까? 1. 설정 앱을 사용하여 키를 탭하고 설정을 클릭합니다. Windows에서는 시스템을 클릭하고 정보를 선택합니다. 고급 시스템 설정을 클릭합니다. 고급 탭으로 이동하여 성능 아래에서 설정을 선택합니다. "시각 효과"를 선택하세요.

Windows 11의 디스플레이 크기 조정과 관련하여 우리 모두는 서로 다른 선호도를 가지고 있습니다. 큰 아이콘을 좋아하는 사람도 있고, 작은 아이콘을 좋아하는 사람도 있습니다. 그러나 올바른 크기 조정이 중요하다는 점에는 모두가 동의합니다. 잘못된 글꼴 크기 조정이나 이미지의 과도한 크기 조정은 작업 시 생산성을 저하시킬 수 있으므로 시스템 기능을 최대한 활용하려면 이를 사용자 정의하는 방법을 알아야 합니다. Custom Zoom의 장점: 화면의 텍스트를 읽기 어려운 사람들에게 유용한 기능입니다. 한 번에 화면에서 더 많은 것을 볼 수 있도록 도와줍니다. 특정 모니터 및 응용 프로그램에만 적용되는 사용자 정의 확장 프로필을 생성할 수 있습니다. 저사양 하드웨어의 성능을 향상시키는 데 도움이 될 수 있습니다. 이를 통해 화면의 내용을 더 효과적으로 제어할 수 있습니다. 윈도우 11을 사용하는 방법
