Jump to content

simple mysql/php question (tagcloud)


imarockstar

Recommended Posts

hey guys ..

 

I have the following code on my site. it is working just find . however ... I want to display the $pmsid data in place of the $userid at the end of the http://www.myspace.com/  url.

 

<div class="tag_cloud_pad_left">

<?php

function get_tag_data() { 
  
  $result = mysql_query("SELECT * FROM plus_signup GROUP BY userid ORDER BY num_votes DESC"); 
  while($row = mysql_fetch_array($result)) { 
    $arr[$row['userid']] = $row['num_votes'];
  } 
  ksort($arr); 
  return $arr; 
}

function get_tag_cloud() 
{

// Default font sizes
$min_font_size = 12;
$max_font_size = 30;


// Pull in tag data
$tags = get_tag_data();

$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(); // create an array to hold tag code
foreach ($tags as $userid => $num_votes) {
$size = $min_font_size + ($num_votes - $minimum_count) 
	* ($max_font_size - $min_font_size) / $spread;
$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
	. '" class="tag_cloud" href="http://www.myspace.com/' . $userid 
	. '" title="\'' . $userid  . '\' returned a count of ' . $num_votes . '">' 
	. htmlspecialchars(stripslashes($userid)) . '</a>';
}
$cloud_html = join("\n", $cloud_tags) . "\n";
return $cloud_html;

}



?>


<h2 class=side>myspace cloud</h2>


<?php print get_tag_cloud(); ?>


</div>

 

 

the above is the full code ...

 

the following is the code that i need changed, but i cant figure it out ..

 

$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
	. '" class="tag_cloud" href="http://www.myspace.com/' . $userid 
	. '" title="\'' . $userid  . '\' returned a count of ' . $num_votes . '">' 
	. htmlspecialchars(stripslashes($userid)) . '</a>';

 

after the myspace.com link i want $userid changed to show the myspace id of that person which is $pmsid. I cant figure out how to pul that info from the mysql quriey and it pop up there.

 

 

Link to comment
Share on other sites

$query = "SELECT * FROM tablename WHERE id = how ever you get the users id LIMIT 1";

if ($result = mysql_query($query)){

    if (mysql_num_rows($result)) {

        $array = mysql_fetch_assoc($result);

        $pmsid = $array['msid??'];

 

 

(array is $array['table name for what you want'];)

Link to comment
Share on other sites

haha ok i know basics... but basicly iv learnt through here...

 

done some topic solvin and posted sum errors... 1 to which took many posts lol...

 

just cos i got lots of posts dont make me good... probs makes me bad lol

 

goota learn sum way tho... least im tryin to give back lol

Link to comment
Share on other sites

I already did that ...

 

but if you notice, I also need to use $userid in the output ...

 

 

$userid = the name of the tag

$pmsid = the myspace id of the user

 

here is the location : http://www.themyspacecontest.com/tag_cloud.php

 

you can see when they are rolled over the link is http://www.myspace.com/($userid)

 

but I need it to be there myspace id whic is stored in $pmsid

Link to comment
Share on other sites

$pmsid isn't included in the output from the function get_tag_data. so i would modify this function to store $pmsid as well:

 

function get_tag_data() { 
  
  $result = mysql_query("SELECT * FROM plus_signup GROUP BY userid ORDER BY num_votes DESC"); 
  while($row = mysql_fetch_array($result)) { 
    // $arr[$row['userid']] = $row['num_votes']; I would change this to:
    $arr[$row['userid']] = array($row['num_votes'], $row['pmsid']);
  } 
  ksort($arr); 
  return $arr; 
}

 

then update all code as required to handle the new array.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.