Русское сообщество fluxbb

Быстрый лёгкий надёжный форумный движок

Вы не вошли.

Объявление

Вы можете внести свой вклад в содержание сайта. Жертвователи попадут в почетную группу "Спонсоры". Поддержать сайт.

#1 2017-03-10 18:34:26

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

add popular topic based on num_views

Hi Mr.Visman, I want to add a grid view of popular topic on my index.php.

And I try to create this on my index

<!-- PopTopik -->
<div class"poptopic">
<?php 

	// How many popular topics do we want to display?
	$numtopik = 4;

	// Fetch pop topics
	$result = $db->query('SELECT id, subject, mainimg, num_views  FROM '.$db->prefix.'topics WHERE id>1 ORDER BY num_views DESC LIMIT '.$numtopik.'', true) or error('Unable to fetch poptopik', __FILE__, __LINE__, $db->error());
	
	while ($pun_pop_topik = $db->fetch_assoc($result))
	{
                $poptopik = '<li><article class="poptopik"><div class="mainimg"><a href="'.fluxrewrite("topic-", pun_htmlspecialchars($pun_pop_topik['id']), pun_htmlspecialchars($pun_pop_topik['subject']), 1, false, false).'"><img width="145" height="100" src="'.pun_htmlspecialchars($pun_pop_topik['mainimg']).'" class="mainimg" alt="'.pun_htmlspecialchars($pun_pop_topik['subject']).'" srcset="'.pun_htmlspecialchars($pun_pop_topik['mainimg']).' 145w, '.pun_htmlspecialchars($pun_pop_topik['mainimg']).' 380w" sizes="(max-width: 145px) 100vw, 145px"></a></div><div class="poptopd"><span class="nama-forum"><a href="URLFORUM" class="forumID">Nama Forum</a></span><strong class="Judul"><a href="'.fluxrewrite("topic-", pun_htmlspecialchars($pun_pop_topik['id']), pun_htmlspecialchars($pun_pop_topik['subject']), 1, false, false).'" title="'.pun_htmlspecialchars($pun_pop_topik['subject']).'">'.pun_htmlspecialchars($pun_pop_topik['subject']).'</a></strong></div></article></li>';
               
	}
?>

	
<?php if ($pun_user['g_id'] == PUN_ADMIN)	
	echo 
	'<h4>Topik Populer</h4>
	<ul>'.$poptopik.'</ul>'
?>
</div>

But I think it still incorrect, because it show only one topic and the topic is not the most popular based on the num_views. 
Can you help me?

Редактировался gandi (2017-03-10 18:35:41)

Offline

#2 2017-03-10 19:57:43

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,203
Сайт

Re: add popular topic based on num_views

<!-- PopTopik -->
<div class"poptopic">
<?php

if ($pun_user['g_id'] == PUN_ADMIN)
{
	// How many popular topics do we want to display?
	$numtopik = 4;
	$poptopik = '';

	// Fetch pop topics
	$result = $db->query('SELECT id, subject, mainimg, num_views  FROM '.$db->prefix.'topics WHERE id>1 ORDER BY num_views DESC LIMIT '.$numtopik, true) or error('Unable to fetch poptopik', __FILE__, __LINE__, $db->error());
	while ($pun_pop_topik = $db->fetch_assoc($result))
	{
		$poptopik .= '<li><article class="poptopik"><div class="mainimg"><a href="'.fluxrewrite("topic-", pun_htmlspecialchars($pun_pop_topik['id']), pun_htmlspecialchars($pun_pop_topik['subject']), 1, false, false).'"><img width="145" height="100" src="'.pun_htmlspecialchars($pun_pop_topik['mainimg']).'" class="mainimg" alt="'.pun_htmlspecialchars($pun_pop_topik['subject']).'" srcset="'.pun_htmlspecialchars($pun_pop_topik['mainimg']).' 145w, '.pun_htmlspecialchars($pun_pop_topik['mainimg']).' 380w" sizes="(max-width: 145px) 100vw, 145px"></a></div><div class="poptopd"><span class="nama-forum"><a href="URLFORUM" class="forumID">Nama Forum</a></span><strong class="Judul"><a href="'.fluxrewrite("topic-", pun_htmlspecialchars($pun_pop_topik['id']), pun_htmlspecialchars($pun_pop_topik['subject']), 1, false, false).'" title="'.pun_htmlspecialchars($pun_pop_topik['subject']).'">'.pun_htmlspecialchars($pun_pop_topik['subject']).'</a></strong></div></article></li>';
	}

?>
	<h4>Topik Populer</h4>
	<ul><?php echo $poptopik ?></ul>
<?php
}
?>
</div>

Редактировался Visman (2017-03-10 20:00:05)

Offline

Подвал доски

Под управлением FluxBB. Хостинг Hostens