使用jQuery制作云标签

jee_asp 2011-06-01 09:01:35
最近在书上的光盘上搞到一个云标签源码,其实跟网上是一样的……
这个是PHP的代码,原本是连接mysql数据库的,因为我学的是sql server,就改了一下,实际运行的时候标签内容不会显示

<?php

//connection information
$host = "localhost";
$user = "sa";
$password = "123";
$database = "poetry";

//make connection
$server = mssql_connect($host, $user, $password);
$connection = mssql_select_db($database, $server);

//query the database
$query = mssql_query("SELECT * FROM tag_cloud");

//start json object
$json = "({ tags:[";

//loop through and return results
for ($x = 0; $x < mssql_num_rows($query); $x++) {
$row = mssql_fetch_assoc($query);

//continue json object
$json .= "{tag:'" . $row["P_name"] . "',freq:'" . $row["frequency"] . "'}";

//add comma if not last row, closing brackets if is
if ($x < mssql_num_rows($query) -1)
$json .= ",";
else
$json .= "]})";
}

//return JSON with GET for JSONP callback
$response = $_GET["callback"] . $json;
echo $response;

//close connection
mssql_close($server);

?>
...全文
406 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jee_asp 2011-06-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hch126163 的回复:]

自己调试!
[/Quote]
php跟mysql都没用过啊……php要链接mssql具体该怎么改?调试出的来的就不用问了啊
toury 2011-06-02
  • 打赏
  • 举报
回复
li.appendTo("#tagList");??
<li>怎么添加到DIV了?应该是添加到<ul>吧
jee_asp 2011-06-02
  • 打赏
  • 举报
回复
自动,来个人帮帮忙啦
jee_asp 2011-06-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 toury 的回复:]

li.appendTo("#tagList");??
<li>怎么添加到DIV了?应该是添加到<ul>吧
[/Quote]
不是啊,div里面显示的就是标签的信息,就是从数据库读取出来的标签,通过jQuery实现大小变化以及动画效果啊。ul里面只是跳转到主页而已。我现在是所有的数据都没有显示,不知道是不是读取数据库的问题,php没用过啊……
hch126163 2011-06-02
  • 打赏
  • 举报
回复
自己调试!
jee_asp 2011-06-02
  • 打赏
  • 举报
回复
自顶……
jee_asp 2011-06-01
  • 打赏
  • 举报
回复
这是页面代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Playground</title>
<link title="green" media="screen" href="css/green.css" type="text/css" rel="stylesheet" />
<link title="green" media="screen" href="css/tagcloud.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function() {

//get tag feed
$.getJSON("tagcloud.php?callback=?", function(data) {

//create list for tag links
$("<ul>").attr("id", "tagList").appendTo("#tagCloud");

//create tags
$.each(data.tags, function(i, val) {

//create item
var li = $("<li>");

//create link
$("<a>").text(val.tag).attr({title:"See all pages tagged with " + val.tag, href:"http://localhost/tags/" + val.tag + ".html"}).appendTo(li);

//set tag size
//li.children().css("fontSize", (val.freq / 10 < 1) ? val.freq / 10 + 1 + "em": (val.freq / 10 > 2) ? "2em" : val.freq / 10 + "em");
var fontSize = val.freq / 10 + "em";
//var fontSize = val.freq + "px";
li.children().css("fontSize", fontSize);

//add to list
li.appendTo("#tagList");

});
});
});
</script>
</head>
<body>
<div id="wrapper">
<h1>jQuery Playground</h1>
<ul id="nav">
<li><a class="current" href="index.html">标签云(Tag Cloud)</a></li>
</ul>
<div id="content">
<div id="tagCloud">

</div>
</div>
<div id="foot">Powered By Dennis Ji.</div>
</div>
</body>
</html>

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧