좋아요,이 스크립트는 특정 질문에 대해 더 많이 입력 된 태그와 덜 작게 입력 된 태그를 표시해야합니다. 그러나 어떤 이유에서 더 크게 입력 된 마지막 태그를 표시하고 카운트 다운중인 것처럼 작게 입력 된 모든 태그를 표시합니다. 이 문제를 해결해야합니다.PHP와 MySQL을 사용하여 MySQL 데이터베이스에 입력 한 횟수에 따라 텍스트를 더 크게 표시하는 방법은 무엇입니까?
내가이 권리를 설명했으면 좋겠습니까?
여기에 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>
@myhut로 tagcount를 할당? @bmac의 답변이 도움이되었습니다. –