最近在书上的光盘上搞到一个云标签源码,其实跟网上是一样的……
这个是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);?>

解决方案 »

  1.   

    这是页面代码<!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>
      

  2.   

    li.appendTo("#tagList");??
    <li>怎么添加到DIV了?应该是添加到<ul>吧
      

  3.   

    不是啊,div里面显示的就是标签的信息,就是从数据库读取出来的标签,通过jQuery实现大小变化以及动画效果啊。ul里面只是跳转到主页而已。我现在是所有的数据都没有显示,不知道是不是读取数据库的问题,php没用过啊……
      

  4.   

    php跟mysql都没用过啊……php要链接mssql具体该怎么改?调试出的来的就不用问了啊