SSI to show the most popular topic from a specified board ?

Started by myaicons, January 27, 2008, 03:15:56 PM

Previous topic - Next topic

myaicons


is it possible to have an SSI to show the most popular topic from a specified board?

either based on posts or views...

... i know there is the Top Topics SSI

Top Topics by View Function: <?php ssi_topTopicsViews(); ?>
which lists the links to the topics

but instead... something that shows the whole message... not just the message link...


thanks in advance! 


P.S. and a random topic from a specific board?


i scratch your back you scratch my back...
funny thing about my back is its located on my...

myaicons

so... is this question too easy to spend time answering? or too hard to answer?   :)
i scratch your back you scratch my back...
funny thing about my back is its located on my...

jamesk

Is it possible -- yes.  With the default SSI.php -- I don't think so.

Is it easy or hard?  Depends on who you ask...  :P

I haven't tried and/or verified but...
If you're not a MySQL person, the easy way is to use the existing ssi_topTopics() to get the $topics['id'] and once you have the topic IDs, you can retrieve the message body by following this thread (bottom half):

http://www.simplemachines.org/community/index.php?topic=214231.msg1377171#msg1377171

If you ARE a MySQL and/or database person, then you can write a query from scratch...


myaicons

Quote from: jamesk on January 29, 2008, 10:27:45 PM<br />Is it possible -- yes.  With the default SSI.php -- I don't think so.  Is it easy or hard?  Depends on who you ask...

ahhh... a brave one ! yay... so am i asking the right person? lol

nope... not a database person...
i prefer the easy route of modifying the ssi call...

i wouldnt imagine it wouldnt be too far from the ssi_topTopics()
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

I will take a stab at it....

This will require you to make 2 changes in the SSI.php file, however, it should not change any part of the original output of SSI.php functions. 

What you are wanting is for the ssi_topTopics(); function to add a request in the database query for the body field from the messages table.

In the original 1.1.4 SSI.php file, in the ssi_topTopics(); function,
find around line 536:
SELECT m.subject, m.ID_TOPIC, t.numViews, t.numReplies
replace with:
SELECT m.subject, m.ID_TOPIC, t.numViews, t.numReplies, m.body

OK... the body field should be available to get the data.  Now we need to put it in the $topics variable....

Around line 551 find:
'id' => $row['ID_TOPIC'],
replace with:

'id' => $row['ID_TOPIC'],
'body' => $row['body'],


Now you should be able to use $output_method = 'array' and call the body field.

myaicons

sounds like that would make sense...  :)

but i guess i didnt clarify from my previous post that i want the body from the top topics by view or by reply

<?php ssi_topTopicsViews(); ?>

or

<?php ssi_topTopicsReplies(); ?>


would it work the same way if i added your code to those functions?


the ssi would look like this:  ??

Quote<?php ssi_topTopicsReplies($num_recent = 1, $exclude_boards = array(1,2,3), $output_method = 'm.body' ); ?>

(if i exluded a few boards)


i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

please reread my post above....  you did not understand it very well....

To help you out a little....  there are only 2 ways to output....  by 'array' or by 'echo'

myaicons

actually... its because i literally do not  understand it...  :-[

im very new and still learning to php and all this coding...


(im on chapter 2 of teach yourself php in 10 mins) lol

i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

Here is a sample using the output method 'array' :

$array = ssi_boardNews($board = $newsboard, $limit = 5, $start = null, $length = 500, $output_method = 'array');

     

if (empty($array))

   echo _NOTOPICSPOSTED;



foreach ($array as $news)

{

echo '

<div style="width:100%" class="option">

        ', $news['icon'], '&nbsp;<strong>', $news['subject'], '</strong><br />

<span style="font-size:x-small">Posted On:&nbsp;&nbsp;', $news['time'], '</span><br />

<span class="option">', $news['body'],' <a href="', $news['href'], '">', _READMORE ,'</a></span></div><br />

<span style="font-size:smaller">', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], ' |

<a href="forum/index.php?action=post;board=', $newsboard ,'">', _POSTNEWSARTICLE ,'</a></span><br /><br />';



if (!$news['is_last'])

echo '<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />';



}

myaicons

yikes... completely lost now...


<?php ssi_topTopicsReplies($output_method= 'array'); ?>
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

yes....  then you can make something similar to the example I posted.  You will need to see what fields are available in the ssi_toptopics...

myaicons

i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

keep testing.....

and when you post a reply, please copy/paste the error here.

myaicons

this is the error i get everytime:

Database Error
Please try again. If you come back to this error screen, report the error to an administrator. 
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

do you have:

require_once("path_to/SSI.php");

at the top of your page?

and if so, is the path correct?

myaicons

yup...
that i know i have right

<?php require('./forum/SSI.php'); ?>

its the rest that is not quite right i think
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

hmmmm....  can you post your page code here?

also, is your ssi function inside the <?  ?>   ???

myaicons



<?php

$array 
ssi_topTopicsReplies($output_method 'array');

     


if (empty(
$array))

   echo 
_NOTOPICSPOSTED;



foreach ($array as $topics)

{

echo '

<div style="width:100%" class="option">

        '
$topics['icon'], '&nbsp;<strong>'$topic['subject'], '</strong><br />

<span style="font-size:x-small">Posted On:&nbsp;&nbsp;'
,$topic['time'], '</span><br />

<span class="option">'
$topic['body'],' <a href="'$topic['href'], '">'_READMORE ,'</a></span></div><br />

<span style="font-size:smaller">'
$topics['link'], $topic['locked'] ? '' ' | ' $topic['comment_link'], ' | 


if (!$topic['
is_last'])

echo '
<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />';



} ?>



i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

you need to put this line immediately after <?php

require_once("path_to/SSI.php");

replace "path_to" with the actual path to your SSI.php file.

myaicons

i actually have this right above it


<?php require('./forum/SSI.php'); ?>
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

try this:


<?php
require('./forum/SSI.php');
$array ssi_topTopicsReplies($output_method 'array');

if (empty(
$array))

   echo 
'No topic posted';

foreach (
$array as $topics)

{
echo 
'

<div style="width:100%" class="option">

        '
$topics['icon'], '&nbsp;<strong>'$topics['subject'], '</strong><br />


<span style="font-size:x-small">Posted On:&nbsp;&nbsp;'
,$topics['time'], '</span><br />
<span class="option">'
$topics['body'],' <a href="'$topics['href'], '">Read more...</a></span></div><br />


<span style="font-size:smaller">'
$topics['link'], $topics['locked'] ? '' ' | ' $topics['comment_link'], ' | 


if (!$topics['
is_last'])

echo '
<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />;

?>


and save it as a php file extention page, for example:  text.php

---you had some variables named $topic instead of $topics

myaicons

i got this error now:


Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/content/html/toptopicpost.php on line 27

line 27:
if (!$topics['is_last'])
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

I guess I did not look at your code closely enough... sorry.

You need to replace this line:
<span style="font-size:smaller">', $topics['link'], $topics['locked'] ? '' : ' | ' . $topics['comment_link'], ' |

with maybe this:

<span style="font-size:smaller">', $topics['link'], $topics['locked'] ? '' : ' | ' . $topics['comment_link'], ' </span>';

myaicons

um... now this:


Parse error: parse error, unexpected $ in /home/content/html/toptopicpost.php on line 31
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog


myaicons




<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($output_method 'array');

if (empty(
$array))

   echo 
'No topic posted';

foreach (
$array as $topics)

{
echo 
'

<div style="width:100%" class="option">

        '
$topics['icon'], '&nbsp;<strong>'$topics['subject'], '</strong><br />


<span style="font-size:x-small">Posted On:&nbsp;&nbsp;'
,$topics['time'], '</span><br />
<span class="option">'
$topics['body'],' <a href="'$topics['href'], '">Read more...</a></span></div><br />


<span style="font-size:smaller">'
$topics['link'], $topics['locked'] ? '' ' | ' $topics['comment_link'], ' </span>';


if (!
$topics['is_last'])

echo 
'<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />;

} ?>




i appreciate all the help  :)
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

see if this works:

<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($output_method 'array');
if (empty(
$array))
   echo 
'No topic posted';
   echo 
'
<table class="ssi_table">'
;
foreach ($array as $topics)
echo '
<tr>
<td align="left">
'
$topics['link'], '
</td>
<td>'
$topics['body'], '</td>
</tr>'
;
echo '
</table>'
;

?>


myaicons

that just gave me another :

Database Error
Please try again. If you come back to this error screen, report the error to an administrator


i think the previous code was more on the right track
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

Firstly, let's get one that is working, then modify it from there.  I looked over the SSI.php file, and the $num_topics variable was left out before.

Try this one:

<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($num_topics 10$output_method 'array');
if (empty(
$array))
   echo 
'No topic posted';
   echo 
'
<table class="ssi_table">'
;
foreach (
$array as $topics)
echo 
'
<tr>
<td align="left" valign="top">
'
$topics['link'], '
</td>
<td valign="top">'
$topics['body'], '</td>
</tr>'
;
echo 
'
</table>'
;

?>

It works for my local install.

I just added the valign so both lines would start at the top of the table cell.

myaicons

woo hoo!

that did it!!! :)

but i tried to add

$exclude_boards = array(1,2,3,4,5)

to exclude some boards from the results but that didnt work

i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

In the SSI.php file, around line 542 find:

AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "

replace with:
AND b.ID_BOARD != $modSettings[recycle_board]" : ''
AND ID_BOARD != array(1,2,3,4,5)) . "


Try that....  I have not tested it, but it may work.

myaicons

nope... that didnt do anything...

i also tried modifying the actual ssi call (just in case i want to repeat it with different boards) but that didnt work for me either


<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($num_topics 1$output_method 'array'$exclude_boards = array(1,2,3,4,5,6));
if (empty(
$array))
   echo 
'No topic posted';
   echo 
'
<table class="ssi_table">'
;
foreach (
$array as $topics)
echo 
'
<tr>
<td align="left" valign="top">
'
$topics['link'], '
<br>
<br>'
$topics['body'], '</td>
</tr>'
;
echo 
'
</table>'
;

?>


either through exclusion or inclusion of boards?  whichever works....


secondly, the icon, date, poster, and comments wont work for it either.... im trying to make it look as close to the board news output as much as possible 

$topics['icon'], $topics['comment_link'], etc...
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

Ok... now you are asking more than that ssi function does.

If you are wanting these kinds of outputs, you will probably need to create your own MySQL query and write the outputs from that, thus bypassing SSI.php functions.

Quotesecondly, the icon, date, poster, and comments wont work for it either.... im trying to make it look as close to the board news output as much as possible

$topics['icon'], $topics['comment_link'], etc...

Those do not work because that ssi function does not "draw out" those variables or database inputs.

Determine what you are fully wanting, then create the query that will supply the needed variables.

myaicons

that is what i feared  :(

i guess those are not necessary... but thanks for all the help!  :D

...all except for the specified board(s) to pull the popular topic from...
would be nice to have...
i scratch your back you scratch my back...
funny thing about my back is its located on my...

spottedhog

don't fear it....  try things....

I would highly recommend downloading this software below.  You can make your own computer a webserver and test out code.  If you have Windoz, you can make a USB thumb drive a webserver, and then test out your code.

http://www.apachefriends.org/en/xampp.html

Personally, I have Kubuntu Linux installed on my dual-boot laptop, so I am able to start up my local webserver from the hard drive and test out all things related to html, php, and mysql.

All that you need to know to make the query you want is contained inside that SSI.php file.  It is just a matter of determining what you want, create the MySQL query for it, and then putting your output into an array.  I know it sounds a bit hard, but I know all you need to know for working examples are in the SSI.php file.

If/when you can write your own query and display the results, you then have a great working knowledge of SMF and other php/mysql applications.

Maybe someone will volunteer to write it for you....  who knows.

myaicons

i scratch your back you scratch my back...
funny thing about my back is its located on my...

Advertisement: