最近在书上的光盘上搞到一个云标签源码,其实跟网上是一样的……
这个是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);?>
这个是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);?>
<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>
<li>怎么添加到DIV了?应该是添加到<ul>吧