?????? ????? ?? PHP

???? (??????) ???? ?? ???????? ???????????????? ????????? ?????. ???-?????? ??? ?????????? ?????????? ?? ???? ??????????? ?? ????????? ????? ???????? ????, ??????? ????????? ?????? ?? ????????. ???????????? ?? ????? ???????? ????? ? ????? ????????? ?? ?????.

????????? ???? ??????????? ? ????????? ??????, ????? ???? ?????????? ???????????. ?? ???? ?????, ????????, ???? ?? ????????? ???? PHP ? HTML.

?????? ????? ??? ???? ? ???????????? ??????????? ????? ?????????? ????? ?????. ??? ???, ??? ?????????? ???, ??? ?????? ????????? ?? ???????? ? ??????.

???????? ????? ? ???? ??????

??? ?????? ???????????, ????? ??????? ????? ??????? ???? ??? ?????? ? ???? ??????. ?????? ??????? ???? ????? ??????? ? ????????? ???? ??? ?????? ?????? ?????? ???????, ??? ??? ?????????? ?????????? ?????? ? ?????? ?? ????? ????? ????? ??????? ? ?????????. ????? ??????????? ??????, ? ?????? ??? ????? "?????? ?? ??????" ????? ????????? ?????? ? ????? ??? ?????? ????????????? ???????.

? ?????????? ?????? ?? ????? ??????? ?? ???????? articles ????????? ?????????:

id | alias | title | text

??????? ? ?????? tags ????? ????????? ???:

id | alias | title

???? alias ????? ??? ???????? ???????? URL ? ???????? ???? ????????? (???????? /articles/hello, ?????? ????????????? ????????? ?????????????? /articles/13).

??? ???????????? ????? ????? ???????? ? ?????? ????????? ????????????? ??????? articles_tags:

id | article_id | tag_id

? ??? ?????? ?????? ????????? ????? ??????-?? ???? ? ?????-?? ???????. ????? ???????, ????? ?? ????? ????? ???? ???????? ?????????? ???????. ????? ????????? ???????? ?????????? ?????? ??? ?????????? ????? ??????????, ?? ??? ??? ??????? ?? ??????? ???? ?????? ??????.

?????????? ?????? ?????

????, ???????????, ??? ?? ????? ????????????? ??? ??????? ? ???????????? ???????. ??? ????? ?????????? ????? ?????????? ???? ? ????????? ?? ??? ??????. ??? ?????? ?????????? ??????? ?????????? ?????, ??????? ????? ?????????? ? ??????:

$tags_count = 30; //--???-?? ????? ? ??????

????? ?????????? ????????? SQL-?????? ??? ????????? ????? ?????????? ?????. ????????? ?? ????? ????????? ???????:

SELECT tags.title              AS title, 
       tags.alias              AS alias, 
       COUNT(tags_articles.id) AS cnt 
FROM   tags 
       INNER JOIN articles_tags
         ON ( articles_tags.tag_id = tags.id ) 
GROUP  BY tags.id 
ORDER  BY cnt DESC 
LIMIT  %tags_count%

? ?????????? ?????? ????????? ??????? ? %tags_count% ????? ?????????? ????? ????????? ?????????:

????????? ???? | ????? ???? | ?????????? ??????????

???? ? ??? ????? ????????????? ?? ????????????. ? ????? ??????? ??????????? ?????? ????? ????????? ?? ????? ???????, ??????? ?????????? ????????????? ???? ?? ??????????. ??? ????? ??????? ??? ?? PHP, ??? ? ? ?????? ???????, ????????? ??????? SQL-??????:

SELECT * 
FROM   (SELECT tags.title              AS title, 
               tags.alias              AS alias, 
               COUNT(tags_articles.id) AS cnt 
        FROM   tags 
               INNER JOIN articles_tags
                 ON ( articles_tags.tag_id = tags.id ) 
        GROUP  BY tags.id 
        ORDER  BY cnt DESC 
        LIMIT  %tags_count%) AS subq
ORDER  BY title

????, ? ??? ??????? ?????? ????? ?????????? ?????. ?????? ?????????? ?????????? ?? ? ?????? ????????? (???????? ??????) ? ??????????? ?? ????????????. ????????? ???????????? ?????? ???????? cnt (?????????? ??????????). ?? ???????????? ???? ???????? ??? ?????? ?????? ??????. ??-??????, ? ??????? ???? ?? ????? ????? ??????? ????????. ??-??????, ? ????? ??? ????????? ????? ?????? ??????????, ?????????? ???? ??? ? ?????? ??? ?????? ??????? ?????? ????.

??????? ??? ??????????, ???????? ??????????? ? ???????????? ?????? ?????? ? ?????? ?????:

$min_real = 8;  //--??????????? ?????? ???? (8pt)
$max_real = 22; //--???????????? ?????? ???? (22pt)

???????????, ??? ????????? ???????????? SQL-??????? ???????? ? ?????????? ret. ????? ?????????? ?????????? ??????????? ? ???????????? ???????? ????????? cnt:

$min_db = 999999;
$max_db = 0;
 
foreach ($ret as $tag)
{
    $min_db = min($min_db, $tag['cnt']);
    $max_db = max($max_db, $tag['cnt']);
}

??? ???? ??? ??? ?????? ????????, ? ?????????? ?????????? ??????? ?? ???????? ???? ????? ?????????? ????? ? ??????????? cnt (?????????? ????????????) ??????????????: 500, 170, 40, 111, 22. ??? ?????????? ?????????? ??? ???? ??????? ???????? ?? 8 (min_real) ?? 22 (max_real). ?? ?????????? ???????????? (max_db = 500) ? ??????????? (min_db = 22) ???????? ????????????. ??? ??????????? ??????? ??????, ??????? ?????????? ?????????? ??? ?? ????????? ???????????? cnt ????????????? ????????:

(cnt - min_db) / (max_db - min_db) * (max_real - min_real) + min_real

? ?????, ???????? ??????????. ???? ??? ?????? ???????????? ? ?????????????.

??? ?????????? ?????? ?????, ? ?????, ????? ????????? ???????? ???:

$tagsarr = array();
foreach ($ret as $tag)
{
    $tagsarr[] = sprintf('<a style="font-size: %dpt;" title="%d" href="/articles/?tag=%s">%s</a>',
                         $min_db == $max_db ? $min_real : ( ($tag['cnt'] - $min_db) / ($max_db - $min_db) * ($max_real - $min_real) + $min_real ),
                         $tag['cnt'],
                         $tag['alias'],
                         $tag['title']
                 );
}
echo implode(', ', $tagsarr);

???????

$min_db == $max_db ? $min_real : ...

????????? ??????? ??????, ????? ???????????? ? ??????????? ???????? ???????????? ?????, ?? ???? ??? ???? ????? ?????????? ????????????. ? ???? ?????? ?????????? ?? ??????????? ???????? ??????. ???????? ???????!

Комментарии

Оставить комментарий »

 
Joker-jar
17 марта 2012, 0:24
#1
 

??????, ???? ? ?????? ????????? ?????? ????? ?? MyFirstSite. ? ???????????? ?? ???????? ? ??????? ??? ????????? ?????? ? ???????????? ??????? ??????? ????????? ?? ?????.

sanina
9 августа 2012, 16:51
#2
 

? ?????? ?? ??????? ??????? ???????? ????????????? ??????? ???????? ???????? ?? ?? ???????

cblock_tags ??????? ???????? ????? ? ? ???? ??? ???????????
id_element ??? id ??????? tag ????????? ???????? ???? ???????? "????" ??????????? ?????? ?? ???????? ????

id_cblock_g ??? ??? ?? ??????? ?????? ????????? ????????

cblock_element ??? ??????? ???????? id_element ????????? ???????

$sql = "SELECT * 
				FROM   ( SELECT ct.tag, COUNT(ce.id_element) AS cnt 
						 FROM   cblock_tags ct 
							   INNER JOIN  cblock_element ce ON ( ce.id_element = ct.id_element AND ce.id_cblock_g = ".intval($group_id)." ) 
						GROUP BY  ct.tag
						ORDER  BY cnt DESC 
						LIMIT  ".$limit." ) AS subq
				ORDER  BY tag ASC";

??? ?????????? ???? ??????????? ????? ????? ??????? ??????? ????? JS ??????????? ???????? ??????????? jQuery TegInput ????? ???? ????? ???????? ????????? ????? ????? ajax

sadex
21 июня 2013, 23:36
#3
 

???????? ??????, ??? ??????????. ?? ???? ????? ?????? ????? ?? ?????? ????? ??????? ????????????

Joker-jar
24 июня 2013, 21:25
#4
 

sadex, ??, ?? ???.

bermuda
30 июня 2013, 21:46
#5
 

????? ??????? ???? ?????? ????? ??????? ??????????!

Joker-jar
1 июля 2013, 9:26
#6
 

bermuda, ?? ? ??????? ? ?????? ????????? ?????????? ????????? ??????.

bermuda
2 июля 2013, 2:24
#7
 

?????? ??? ??? ???????.
??? ? ????? ?????? ????? ???????? ???????? ?????

original-mix
remix

? ????? ???? ?????

www.site.ru/tags/original-mix/
www.site.ru/tags/remix/

?? ???? ?????????? ??? ??? ? ????? ????? ?????? ???? ????? tags ? ??????? ???? ????? original-mix ? remix ? ? ?????? ?? ??? ??? ?? ????? index.php ????

??? ????? ??????????? ????? ????????

www.site.ru/index.php?tags=original-mix
www.site.ru/index.php?tags=remix

Joker-jar
4 июля 2013, 8:16
#8
 

?, ? ?????. ???, ??????? ????? tags ?? ?????, ???? URL-?????? ??????????? ??? ?????? ??????????, ? ??????? ????? ???????? ?????:

http://www.myfirstsite.ru/qna/16
http://www.myfirstsite.ru/qna/2

bermuda
5 июля 2013, 0:32
#9
 

??????? ???? ???????????

vitalik-758153
27 июля 2013, 8:28
#10
 

???????? ??????, ??? ??????????

Оставить комментарий

Ваше имя
 
Ваш e-mail
 
Комментарий