Ver Mensaje Individual
  #10 (permalink)  
Antiguo 10/08/2014, 08:50
Avatar de iEnrique
iEnrique
 
Fecha de Ingreso: abril-2013
Ubicación: España
Mensajes: 346
Antigüedad: 11 años
Puntos: 5
Respuesta: Hashtags del momento

Perdón por no contestar antes, tenía visita en casa y no podía dejar de atenderlos ni un segundo para contestar a tu respuesta. De nuevo muchas gracias de antemano por el interés.

Pues verás te pongo un ejemplo que te muestro, pongamos una tabla como esta:
Código SQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `hashtags` (
  2.   `hashtag_id` INT(11) NOT NULL AUTO_INCREMENT,
  3.   `hashtag_content` VARCHAR(139) NOT NULL,
  4.   `hashtag_date` datetime NOT NULL,
  5.   `hashtag_language` VARCHAR(5) NOT NULL,
  6.   `hashtag_message` INT(11) NOT NULL,
  7.   PRIMARY KEY (`hashtag_id`)
  8. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=61 ;
  9.  
  10. INSERT INTO `hashtags` (`hashtag_id`, `hashtag_content`, `hashtag_date`, `hashtag_language`, `hashtag_message`) VALUES
  11. (1, 'cerveza', '2014-08-05 04:44:27', 'es', 1),
  12. (2, 'hello', '2014-08-10 01:22:13', 'es', 2),
  13. (3, 'miedo', '2014-08-10 01:22:34', 'es', 3),
  14. (4, 'miedo', '2014-08-10 01:44:35', 'es', 4),
  15. (5, 'hello', '2014-08-10 02:17:54', 'es', 5),
  16. (6, 'jajaja', '2014-08-10 02:30:08', 'es', 6),
  17. (7, 'hashtags', '2014-08-10 02:30:23', 'es', 7),
  18. (8, 'hashtags', '2014-08-10 02:30:45', 'es', 8);

Y en este caso, este código:
Código PHP:
Ver original
  1. <?php $reporte_ultimos_dias = 7;
  2.     $lapso_de_intervalo = 30;
  3.     $sql = mysqli_query($mysqli, "SELECT info.hashtag_content, SUM(info.cantidad) menciones, ( (CEIL( info.intervalo_actual / ( TIMESTAMPDIFF (  MINUTE,
  4.                                                        DATE_SUB(NOW(), INTERVAL $reporte_ultimos_dias DAY),
  5.                                                        NOW()
  6.                                                      ) / $lapso_de_intervalo)
  7.                                                ) ) * info.cantidad) puntuacion
  8.                                    FROM (
  9.                                        SELECT
  10.                                            hashtag_content,
  11.                                            CEIL(   ( TIMESTAMPDIFF(  MINUTE,
  12.                                                        DATE_SUB(NOW(), INTERVAL $reporte_ultimos_dias DAY),
  13.                                                        hashtag_date
  14.                                                       ) / $lapso_de_intervalo)
  15.                                                ) intervalo_actual,
  16.                                            COUNT(DISTINCT hashtag_id) cantidad
  17.                                        FROM hashtags
  18.                                        WHERE ( hashtag_date >= DATE_SUB(NOW(), INTERVAL $reporte_ultimos_dias DAY) )
  19.                                        GROUP BY intervalo_actual, hashtag_content
  20.                                        HAVING intervalo_actual > 0
  21.                                    ) info  
  22.                                    GROUP BY info.hashtag_content
  23.                                    ORDER BY puntuacion DESC");
  24.     while($hashtag = mysqli_fetch_array($sql))
  25.         echo '<div><a href="/i/hashtag/'.$hashtag['hashtag_content'].'" class="hcolor">#'.$hashtag['hashtag_content'].'</a></div>'; ?>

Lo he pasado a MySqli con sentencias no preparadas para que sea más fácil de controlar. Bueno, una vez tengas esto, ponlo en funcionamiento. Verás como #cerveza que es el primer hashtag que se creó y también el más antiguo, se encuentra en segundo lugar o tercero, cuando hay otros más recientes con la misma o igual cantidad de veces que aparece.

La verdad es que he realizado el cambio que me has dicho y el funcionamiento a mejorado ligeramente.

Gracias por todo .