好的,我有这个脚本应该显示对于某个问题输入的标签要大几倍,而输入的标签要小一些。但由于某种原因,它显示最后输入的标签更大,并显示在它之前输入的所有标签,就像它正在倒计时一样。我需要解决这个问题。
我希望我解释得对吗?
这是 MySQL 表。
CREATE TABLE questions_tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag_id INT UNSIGNED NOT NULL,
users_questions_id INT UNSIGNED NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
这是我的 PHP 脚本。
<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "sitename";
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);
function tag_info() {
$result = mysql_query("SELECT questions_tags.*, tags.* FROM questions_tags INNER JOIN tags ON tags.id = questions_tags.tag_id WHERE questions_tags.users_questions_id=3 ORDER BY users_questions_id DESC");
while($row = mysql_fetch_array($result)) {
$arr[$row['tag']] = $row['id'];
}
ksort($arr);
return $arr;
}
function tag_cloud() {
$min_size = 10;
$max_size = 30;
$tags = tag_info();
$minimum_count = min(array_values($tags));
$maximum_count = max(array_values($tags));
$spread = $maximum_count - $minimum_count;
if($spread == 0) {
$spread = 1;
}
$cloud_html = '';
$cloud_tags = array();
foreach ($tags as $tag => $count) {
$size = $min_size + ($count - $minimum_count)
* ($max_size - $min_size) / $spread;
$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px'
. '" class="tag_cloud" href="http://www.example.com/tags/' . $tag .'/'
. '" title="\'' . $tag . '\' returned a count of ' . $count . '">'
. htmlspecialchars(stripslashes($tag)) . '</a>';
}
$cloud_html = join("\n", $cloud_tags) . "\n";
return $cloud_html;
}
?>
<div id="wrapper">
<?php print tag_cloud(); ?>
</div>