Firefox PHP

Hack done to list 10 newest topics

Posted by Timothy Ha 
This hack was done to see the newest 10 posts before listing the thread subjects and so on. Phorum separates threads on several pages and usually it is difficult to find new posts if they are replies to some old threads. With this hack all new posts will be \"on the surface\". A working forum with this hack is at [biblerussia.org]. Everything there is in Russian, but you can SEE how it works. :-)

Put the code below in read.php and list.php before the first mention of:
<table width=\"<?PHP echo $ForumTableWidth; ?>\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\">

Cheers,
Timothy.

// -- the hack ---------------------------------------------
// getting last 10...
$sSQL = \"Select id,thread,subject,author,datestamp from $ForumTableName where approved=\'Y\' order by datestamp desc limit 10\";
$msg_list = new query($DB, $sSQL);
$newtopics = \"\";

$rec=$msg_list->getrow();
while(is_array($rec)){
$newtopics .= date_format($rec[\"datestamp\"]).\" \".$rec[\"author\"].\": <a href=\\\"$read_page.$ext?f=$num&t=\".$rec[\"thread\"].\"&i=\".$rec[\"id\"].\"\\\">\".$rec[\"subject\"].\"</a><br>\\n\";
$rec=$msg_list->getrow();
}
?>
</center>
<?
print $newtopics;
?>
<p>
<center>
<table width=\"<?PHP echo $ForumTableWidth; ?>\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\">
hey, i think u mess up the code a little, can u repost it plz
The code is right - this phorum just added a forward slash before all quotes... remove all the forward slashes from the code part and it will work.
What if you would like to list only those not read by the visitor?
I am working on something like this, but cant make it work...dont yet know how to get that cookie info on which msgs are read or not....


Eivind
I took the liberty of reposting this hack, beautified with a nice table :-) Hope y ou dont mind. I included the list count as a global so you can include it in the URL or whatever...



// ------ GETTING LAST N POSTS IN NICE TABLE -- HACK ---------------
global $N;
(IsSet($N))? $N = $N : $N = 10;
$easi_query = "Select id,thread,subject,author,datestamp from $ForumTableName where approved='Y'
order by datestamp desc limit $N";
$easi_result = new query($DB, $easi_query);
$newtopics = "\n<!-- START HACK TABLE -- EAS 140301 -->
<table align=left width=\"$ForumTableWidth\" border=0 cellpadding=1 cellspacing=0>
<tr><td colspan=3><font face=helvetica color=gray size=-2>Latest $N postings, regardless of topic:</font>\n</td></tr>
<tr bgcolor=\"#999999\">
<td><font color=white>Date</font></td>
<td><font color=white>Author</font></td>
<td><font color=white>Subject</font></td></tr>\n";
$ctr = 0;
$row = $easi_result->getrow();
while(is_array($row)){
$id = $row["id"];
$thread = $row["thread"];
$date = date_format($row["datestamp"]);
$author = $row["author"];
$subject = $row["subject"];
($ctr % 2 == 0)? $color = "#ffffff" : $color = "#eeeeee";

$newtopics .= "<TR bgcolor=\"$color\"><TD>$date</TD><TD>$author</TD>
<TD><a href=\"read.php?f=$f&i=$id&t=$thread\">$subject</a>$new</TD></TR>\n";
$ctr++;
$row = $easi_result->getrow();
}// end while

print $newtopics;
print("</table></center>");

echo "<BR clear=all><BR><BR><center><table width=\"$ForumTableWidth\" cellspacing=\"0\"
cellpadding=\"3\" border=\"0\">\n";


// ---------------- END HACK -------------------------
You can also put &n=100 as i did with top X authors hack

Vulpes
Hi! I wanted a list of the N latest messages not already read by me and took the liberty of starting with Timothy Ha\'s nice hack that lists the 10 latest topics. I extended the hack to work with the cookie gallery in phorum so that if it finds the phorum cookies (for this phorum) on your computer, it will be able to list only those you haven\'t read already. Otherwise, simply the N latest are shown (you can include N in the URL, if not it is hardcoded to N=10).

Since this was OK with Timothy, I post it both as a new hack and under the thread for Timothy\'s original hack.
Code below and in attached textfile. To be included at the same spot that mr. Ha mentions; in \"list.php\" just before the first mention of <table width=\\\"<?PHP echo $ForumTableWidth; ?>\\\" cellspacing=\\\"0\\\" cellpadding=\\\"3\\\" border=\\\"0\\\"> .

Best regards,

Eivind

--------------

// ------ GETTING LAST N POSTS IN NICE TABLE -- HACK 1403 EAS ---------------

global $UseCookies, $haveread, $use_haveread, $old_message;
global $N;
(IsSet($N))? $N = $N : $N = 10;

if($UseCookies){
// --Using cookies--
if(IsSet($old_message) && $old_message > 0){
if($use_haveread && count($haveread) > 0){
$hread = array();
foreach($haveread as $i => $v)
array_push($hread, $i);
$hread = implode(\", \", $hread);
$add = \" AND ( (id>$old_message) AND (id NOT IN ($hread)) ) \";
}else{
$add = \" AND id>$old_message \";
}
$latest_txt = \"Latest postings unread by you, regardless of topic\";
}else{// --old_message not set--
$add = \"\";
$latest_txt = \"Latest $N postings, regardless of topic\";
}
}else{
// --No cookie-using--
$add = \"\";
$latest_txt = \"Latest $N postings, regardless of topic\";
}// END cookie galore

$easi_query = \"Select id,thread,subject,author,datestamp from $ForumTableName where approved=\'Y\'
$add order by datestamp desc limit $N\";
$easi_result = new query($DB, $easi_query);
$newtopics = \"\\n<!-- START HACK TABLE -- EAS 140301 -->
<table align=left width=\\\"$ForumTableWidth\\\" border=0 cellpadding=1 cellspacing=0>
<tr><td colspan=3>
<font face=helvetica color=gray size=-2>$latest_txt</font>\\n</td></tr>
<tr bgcolor=\\\"#999999\\\">
<td><font color=white>Date</font></td>
<td><font color=white>Author</font></td>
<td><font color=white>Subject</font></td></tr>\\n\";
$ctr = 0;
$row = $easi_result->getrow();
while(is_array($row)){
$id = $row[\"id\"];
$thread = $row[\"thread\"];
$date = date_format($row[\"datestamp\"]);
$author = $row[\"author\"];
$subject = $row[\"subject\"];
$new = \"\";
($ctr % 2 == 0)? $color = \"#ffffff\" : $color = \"#eeeeee\";

$newtopics .= \"<TR bgcolor=\\\"$color\\\"><TD>$date</TD><TD>$author</TD>
<TD><a href=\\\"read.php?f=$f&i=$id&t=$thread\\\">$subject</a>$new</TD></TR>\\n\";
$ctr++;
$row = $easi_result->getrow();
}// end while

$newtopics .= \"</table></center><BR clear=all><BR>\\n\";
if($ctr > 0) print $newtopics;

echo \"<BR><center><table width=\\\"$ForumTableWidth\\\" cellspacing=\\\"0\\\"
cellpadding=\\\"3\\\" border=\\\"0\\\">\\n\";


// ---------------- END HACK 1403 EAS -------------------------
Your attachement didn't arrive and code is too messy in:

$hread = implode(\", \", $hread);

What should we read in.

Best,

Lopo
Nook
RE: Hack done to list 10 newest topics
January 11, 2002 12:10PM
how to do if i want 10 last messages of 4 lists in one phorum ?
Really Interesting
February 09, 2002 11:15AM
I installed this hack and it works fine. However in the threads the last ($n=10) message listed in that last 10 table, loses it's link in the threads table. The 10th message gets a <b> tag instead of the <a href> tag.

Any ideas?

Thanks.
Again better
February 18, 2002 06:06PM
My code with hits implemented :
1) Dont forget <? and ?> at the first and last line!!
2) Post code BEFORE
<table width=\"<?PHP echo $ForumTableWidth; ?>\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\">


// ------ GETTING LAST N POSTS IN NICE TABLE -- HACK ---------------
global $N;
(IsSet($N))? $N = $N : $N = 10;
$easi_query = "Select id,thread,subject,author,datestamp,views from $ForumTableName where approved='Y'
order by datestamp desc limit $N";
$easi_result = new query($DB, $easi_query);
$newtopics = "\n<!-- START HACK TABLE -- EAS 140301 -->
<table align=center width=\"$ForumTableWidth\" border=0 cellpadding=1 cellspacing=0>
<tr><td ALIGN=CENTER colspan=3><font face=helvetica color=black size=-2>Nejnovìjších $N pøíspìvkù v diskuzi pilotù:</font>\n</td></tr>
<tr bgcolor=\"#999999\">
<td><font color=white>Date</font></td>
<td><font color=white>Author</font></td>
<td><font color=white>Subject</font></td>
<td><font color=white>Ètenost</font></td>
</tr>\n";
$ctr = 0;
$row = $easi_result->getrow();
while(is_array($row)){
$id = $row["id"];
$thread = $row["thread"];
$date = date_format($row["datestamp"]);
$author = $row["author"];
$subject = $row["subject"];
$views = $row["views"];
($ctr % 2 == 0)? $color = "#ffffff" : $color = "#eeeeee";

$newtopics .= "<TR bgcolor=\"$color\"><TD>$date</TD><TD>$author</TD>
<TD><a href=\"read.php?f=$f&i=$id&t=$thread\">$subject</a>$new</TD><TD>$views</TD></TR>\n";
$ctr++;
$row = $easi_result->getrow();
}// end while

print $newtopics;
print("</table></center>");

echo "<BR clear=all><BR><BR><center><table width=\"$ForumTableWidth\" cellspacing=\"0\"
cellpadding=\"3\" border=\"0\">\n";
// ---------------- END HACK -------------------------

3) Then altere table phorums for add views columns

Go in MYSQL as user root use phorums;
ALTER TABLE <phorums> ADD views INT(7) DEFAULT '0';
exit


4) Add the hiting code to read.php
before this line (Line 153):
$msg_body = new query($DB, $sSQL);

//---add--hits----code---------
$vSQL = "SELECT views FROM $ForumTableName WHERE id=".$id;
$result = mysql_query($vSQL);
list($views) = mysql_fetch_row($result);
$vSQL = "UPDATE $ForumTableName SET views=" . ($views + 1) . " WHERE id=$id";
mysql_query($vSQL);
//---end---------

Thats it, and now look at the result: [phorum.aeroomni.com]
I think, this combination is more easy for newbabies in PHP like me :) Programing is for me fun in free time (my job - pilot) . Just message for these like me here:-)) Read always ALL !!! the posts from the programers!! In each post you find somethink important, what makes the think what you like to install work:-))

P.S: eivind sivertsen !!! Thanks a LOT!!! Gooood job!!! Nice table.
Paul
Sorry, you do not have permission to post/reply in this forum.