root/devel-backup/units/search/tags_display.php

Revision 106, 1.1 kB (checked in by sven, 3 years ago)

some sql optimisation
- count(*) is more efficient than equivalent count(fieldname) of primary key
- unlefting left joins where the right is required
- "a IN (x,y)" is easier to optimise than "a=x OR a=y"

  • Property svn:eol-style set to native
Line 
1 <?php
2
3     // Display popular tags
4     
5         $run_result .= "<p>" . gettext("The following is a selection of keywords used within this site. Click one to see related users, weblog posts or objects.") . "</p>";
6     
7         $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ")";
8         $tags = db_query("select tag, count(*) as number from tags where tags.access = 'PUBLIC' group by tag order by rand() limit 200");
9         if (sizeof($tags) > 0) {
10             
11             $max = 0;
12             foreach($tags as $tag) {
13                 if ($tag->number > $max) {
14                     $max = $tag->number;
15                 }
16             }
17             foreach($tags as $tag) {
18                 if ($tag->number > ($max * 0.5)) {
19                     $size = "160%";
20                 } else if ($tag->number > ($max * 0.35)) {
21                     $size = "140%";
22                 } else if ($tag->number > 4) {
23                     $size = "120%";
24                 } else if ($tag->number > 1) {
25                     $size = "100%";
26                 } else {
27                     $size = "80%";
28                 }
29                 $tag->tag = stripslashes($tag->tag);
30                 $run_result .= "<a href=\"".url."tag/".urlencode(htmlentities(strtolower(($tag->tag))))."\" style=\"font-size: $size\" title=\"".htmlentities($tag->tag)." (" .$tag->number. ")\">";
31                 $run_result .= $tag->tag . "</a> ";
32             }
33             
34         }
35
36 ?>
Note: See TracBrowser for help on using the browser.