Foros del Web » Programando para Internet » PHP »

Problema con php ... Una mano por favor

Estas en el tema de Problema con php ... Una mano por favor en el foro de PHP en Foros del Web. EL CODIGO QUE ESTA MAS ABAJO sirve para ""RELACIONAR ARTICULOS ENTRE SI ... POR MEDIO DE UNA PALABRA"" ... cuando estoy cargando el articulo u ...
  #1 (permalink)  
Antiguo 21/10/2012, 19:09
 
Fecha de Ingreso: junio-2008
Mensajes: 82
Antigüedad: 15 años, 10 meses
Puntos: 2
Problema con php ... Una mano por favor

EL CODIGO QUE ESTA MAS ABAJO sirve para ""RELACIONAR ARTICULOS ENTRE SI ... POR MEDIO DE UNA PALABRA"" ... cuando estoy cargando el articulo u nota periodistica .. agrego la palabra por ejemplo "hola" en el campo "meta palabra" y en todo los articulos que agregue la palabra "hola" ... se relacionan ... es interesante su uso.. yo nunca lo habia usado y ahora que lo quiero hacer me encuentro con el problema que si tengo 100 relaciones la lista seria muy larga .....

COMO HAGO PARA MOSTRAR SOLO LAS ULTIMAS 10 RELACIONES ENTRE ARTICULOS .. y las otras paginar o directamente no mostrarlas .... si alguien puede dar una mano .. agradecido

aca dejo el codigo



defined('_JEXEC') or die;

require_once JPATH_SITE.'/components/com_content/helpers/route.php';

abstract class modRelatedItemsHelper
{
public static function getList($params)
{
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$user = JFactory::getUser();
$userId = (int) $user->get('id');
$count = intval($params->get('count', 5));
$groups = implode(',', $user->getAuthorisedViewLevels());
$date = JFactory::getDate();

$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');

$temp = JRequest::getString('id');
$temp = explode(':', $temp);
$id = $temp[0];

$showDate = $params->get('showDate', 0);
$nullDate = $db->getNullDate();
$now = $date->toSql();
$related = array();
$query = $db->getQuery(true);

if ($option == 'com_content' && $view == 'article' && $id)
{
// select the meta keywords from the item .... relacionar "esa" palabra entre los articulos

$query->select('metakey');
$query->from('#__content');
$query->where('id = ' . (int) $id);
$db->setQuery($query);

if ($metakey = trim($db->loadResult()))
{
// explode the meta keys on a comma
$keys = explode(',', $metakey);
$likes = array ();

// assemble any non-blank word(s)
foreach ($keys as $key)
{
$key = trim($key);
if ($key) {
$likes[] = $db->escape($key);
}
}

if (count($likes))
{
// select other items based on the metakey field 'like' the keys found
$query->clear();
$query->select('a.id');
$query->select('a.title');
$query->select('DATE_FORMAT(a.created, "%Y-%m-%d") as created');
$query->select('a.catid');
$query->select('cc.access AS cat_access');
$query->select('cc.published AS cat_state');

//sqlsrv changes
$case_when = ' CASE WHEN ';
$case_when .= $query->charLength('a.alias');
$case_when .= ' THEN ';
$a_id = $query->castAsChar('a.id');
$case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
$case_when .= ' ELSE ';
$case_when .= $a_id.' END as slug';
$query->select($case_when);

$case_when = ' CASE WHEN ';
$case_when .= $query->charLength('cc.alias');
$case_when .= ' THEN ';
$c_id = $query->castAsChar('cc.id');
$case_when .= $query->concatenate(array($c_id, 'cc.alias'), ':');
$case_when .= ' ELSE ';
$case_when .= $c_id.' END as catslug';
$query->select($case_when);
$query->from('#__content AS a');
$query->leftJoin('#__content_frontpage AS f ON f.content_id = a.id');
$query->leftJoin('#__categories AS cc ON cc.id = a.catid');
$query->where('a.id != ' . (int) $id);
$query->where('a.state = 1');
$query->where('a.access IN (' . $groups . ')');
$concat_string = $query->concatenate(array('","', ' REPLACE(a.metakey, ", ", ",")', ' ","'));
$query->where('('.$concat_string.' LIKE "%'.implode('%" OR '.$concat_string.' LIKE "%', $likes).'%")'); //remove single space after commas in keywords)
$query->where('(a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).')');
$query->where('(a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).')');

// Filter by language
if ($app->getLanguageFilter()) {
$query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')');
}

$db->setQuery($query);
$qstring = $db->getQuery();
$temp = $db->loadObjectList();

if (count($temp))
{
foreach ($temp as $row)
{
if ($row->cat_state == 1)
{
$row->route = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug));
$related[] = $row;
}
}
}
unset ($temp);
}
}
}

return $related;
}
}
  #2 (permalink)  
Antiguo 21/10/2012, 20:29
Avatar de Nemutagk
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: México
Mensajes: 2.633
Antigüedad: 20 años
Puntos: 406
Respuesta: Problema con php ... Una mano por favor

Joder, tu código es muy largo, para colmo lo publicas directamente sin usar highlight para facilitar su lectura, en fin, la verdad es que no eh leido todo tu código (por lo antes comentado), pero en SQL existe la sentencia LIMIT que puede limitar los items devueltos por la DB
__________________
Listo?, tendría que tener 60 puntos menos de IQ para considerarme listo!!!
-- Sheldon Cooper
http://twitter.com/nemutagk
PD: No contestaré temas vía mensaje personal =)

Etiquetas: favor, mano, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:45.