Ver Mensaje Individual
  #5 (permalink)  
Antiguo 27/11/2007, 13:27
Chemix
 
Fecha de Ingreso: mayo-2003
Mensajes: 92
Antigüedad: 23 años, 4 meses
Puntos: 0
Re: Sistema tag-cloud

Hola Compex, gracias por tu interes ,.. pero no va,.. (

Con esta consulta...

Código PHP:
function get_tag_data() {
$result = mysql_query("SELECT * FROM tags WHERE id='$CATEGORIA' GROUP BY tag ORDER BY relevancia DESC");
while(
$row = mysql_fetch_array($result)) {
$arr[$row['tag']] = $row['relevancia'];
}
ksort($arr);
return 
$arr;
} 
Me tira estos errores,... ufffffffff

Código PHP:
Warning: ksort() expects parameter 1 to be array, null given in /home/chemuska/domains/chemuska.com/public_html/admin/functions.php on line 106

Warning
: array_values() [function.array-values]: The argument should be an array in /home/chemuska/domains/chemuska.com/public_html/admin/functions.php on line 119

Warning
: Wrong parameter count for min() in /home/chemuska/domains/chemuska.com/public_html/admin/functions.php on line 119

Warning
: array_values() [function.array-values]: The argument should be an array in /home/chemuska/domains/chemuska.com/public_html/admin/functions.php on line 120

Warning
: Wrong parameter count for max() in /home/chemuska/domains/chemuska.com/public_html/admin/functions.php on line 120

Warning
: Invalid argument supplied for foreach() in /home/chemuska/domains/chemuska.com/public_html/admin/functions.php on line 129 

Voy a exponer el tema de nuevo,...

Tengo la tabla de "tags"

Código PHP:
CREATE TABLE `tags` (
  `
id_tag` int(11) NOT NULL auto_increment,
  `
tag` varchar(100) collate utf8_unicode_ci NOT NULL default '',
  `
relevancia` int(11) NOT NULL default '0',
  
PRIMARY KEY  (`id_tag`)
) 
ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=57 ; 
las funciones

Código PHP:
function get_tag_data() { 
$result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY relevancia DESC"); 
while(
$row = mysql_fetch_array($result)) { 
$arr[$row['tag']] = $row['relevancia'];
} 
ksort($arr); 
return 
$arr; 
}

function 
get_tag_cloud() {

    
$min_font_size = 10;
    
$max_font_size = 20;

    
$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(); 
    foreach (
$tags as $tag => $relevancia) {
        
$size = $min_font_size + ($relevancia - $minimum_count) 
            * (
$max_font_size - $min_font_size) / $spread;
        
$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            
. '" class="tag_cloud" href="http://www.chemuska.com/search.php?swords=' . $tag 
            
. '" title="\'' . $tag  . '\' haz click para ver resultados">' 
            
. htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    
$cloud_html = join("\n", $cloud_tags) . "\n";
    return 
$cloud_html;

} 
,... todo esto funciona perfecto, se imprime cada tag con su correspondiente relevancia

ahora quiero hacer la consulta aqui

Código PHP:
function get_tag_data() { 
$result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY relevancia DESC"); 
while(
$row = mysql_fetch_array($result)) { 
$arr[$row['tag']] = $row['relevancia'];
} 
ksort($arr); 
return 
$arr; 
} 
relacionando cada tag con una categoria,... para lo que añadi el campo "id" en la tabla de "tags" como me dijo Compex

Código PHP:
CREATE TABLE `tags` (
  `
id_tag` int(11) NOT NULL auto_increment,
  `
id` int(11) NOT NULL default '0',
  `
tag` varchar(100) collate utf8_unicode_ci NOT NULL default '',
  `
relevancia` int(11) NOT NULL default '0',
  
PRIMARY KEY  (`id_tag`)
) 
ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=57 ; 
la tabla de categorias es "categories"

Código PHP:
CREATE TABLE `categories` (
  `
id` int(11) NOT NULL auto_increment,
  `
parent` int(11) default NULL,
  `
title` text collate utf8_unicode_ci,
  `
path` text collate utf8_unicode_ci,
  `
description` text collate utf8_unicode_ci,
  `
keywords` text collate utf8_unicode_ci,
  `
date` date NOT NULL default '0000-00-00',
  
PRIMARY KEY  (`id`)
) 
ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=238 ; 
,... por favor a ver si se implica alguien mas,.. creo que es interesante para mas usuarios,... si alguien lo quiere le puedo pasar un sencillo admin formulario que tengo hecho para añadir cada tag en la db "Añadir" "Editar" "Borrar" con los 4 campos de cada tag "id_tag" ("id" , con este campo quiero hacer la relacion con las categorias, osea que de momento es inutil) "tag" y "relevancia"

enga a ver si alguien me da un empujonnnnn

Saludos