Jump to content

Better Method of a Member Cloud


Cultureshock

Recommended Posts

I assume most people know how tag clouds work, where the tags most used are bigger and the least used tags are smaller. This is the basic function of my member cloud.

 

I created the code below from scratch, however I'd rather the data compare itself to each other and have the biggest poster the biggest font size (40px) and the smallest poster the smaller font size (15px) and everyone in between where they should be.

 

Assume the limit was 5 instead of 20 as in the code.

If:

Member 1 has 10 posts

Member 2 has 11 posts

Member 3 has 12 posts

Member 4 has 13 posts

Member 5 has 14 posts

 

I'd want Member 1 to be 15px and member 5 to be 40px, and everyone in between where they should be (I assume this would involve percentages.)

 

A more accurate/ more likely example:

Member 1 has 50 posts

Member 2 has 2 posts

Member 3 has 72 posts

Member 4 has 90 posts

Member 5 has 54 posts

 

I'd want Member 2 to be 15px and member 4 to be 40px, and everyone in between where they should be, regardless of what there actual post count is. I just want smallest smallest and largest largest.

 

 

 

 

$allmembersresult = mysql_query("SELECT * FROM users ORDER BY RAND() DESC LIMIT 20");
while($row = mysql_fetch_array($allmembersresult)){
$newuid = $row['id'];
$newusername = $row['username'];
$ifadmin = $row['admin'];

$postnumresult = mysql_query("SELECT * FROM content WHERE uid='$newuid' GROUP BY cid");
$postnum = mysql_num_rows($postnumresult);

?>

<a href="/us.php?find=<?php echo $newuid;?>" style="text-transform:none;
<?php
if($postnum == 0){
echo "font-size:15px;";
}else if($postnum > 0 && $postnum <= 5){
echo "font-size:20px;";
}else if($postnum > 5 && $postnum <= 15){
echo "font-size:30px;";
}else if($postnum > 15 && $postnum <= 30){
echo "font-size:40px;";
}; 

/* etcetc */

if($ifadmin == "yes"){
echo "font-style:italic;font-family:georgia;";
};
if($uid == "$newuid"){
echo "color:green;";
};
?>
">
<?php echo $newusername." (".$postnum.")"; ?>
, </a> 

<?php }; ?>

 

I'd be happy to elaborate if need be! thanks!

Link to comment
https://forums.phpfreaks.com/topic/182464-better-method-of-a-member-cloud/
Share on other sites

function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )
{
$minimumCount = min($data);
$maximumCount = max($data);
$spread       = $maximumCount - $minimumCount;
$cloudHTML    = '';
$cloudTags    = array();

$spread == 0 && $spread = 1;

foreach( $data as $tag => $count )
{
	$size = $minFontSize + ( $count - $minimumCount )
		* ( $maxFontSize - $minFontSize ) / $spread;
	$cloudTags[] = '<a style="font-size: ' . floor( $size ) . 'px'
	. '" class="tag_cloud" href="#" title="\'' . $tag  .
	'\' returned a count of ' . $count . '">'
	. htmlspecialchars( stripslashes( $tag ) ) . '</a>';
}

return join( "\n", $cloudTags ) . "\n";
}
/**************************
****   Sample usage    ***/
$arr = Array('Actionscript' => 35, 'Adobe' => 22, 'Array' => 44, 'Background' => 43,
'Blur' => 18, 'Canvas' => 33, 'Class' => 15, 'Color Palette' => 11, 'Crop' => 42,
'Delimiter' => 13, 'Depth' => 34, 'Design' => 8, 'Encode' => 12, 'Encryption' => 30,
'Extract' => 28, 'Filters' => 42);
echo getCloud($arr, 12, 36);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.