PDA

View Full Version : latest threads from $forumXX


remal
04-14-2003, 01:37 PM
hello, iam searching for a hack or just a small php script that list the latest post or threads from a specific forum..

i found a few scripts thats list the latest threads, but you cant specifi a particular forum, they list the lasx XX threads from all of the forum.

if there is a script to do that it will be terrific, if not, what is the SQL query i need to do in order to get the last XX post or threads from a forumID...

The_Cyberdemon
04-14-2003, 02:21 PM
Umm, do something like this on your index.php file:
$numbersthreads=$DB_site->query_first('SELECT COUNT(*) AS threads,MAX(threadid) AS maxthread FROM thread WHERE forumid=1');
$numberthreads=number_format($numbersthreads['threads']);
$getnewestthreadforum=$DB_site->query_first("SELECT threadid,title FROM thread WHERE threadid=$numbersthreads[maxthread]");
$newthread=$getnewestthreadforum['title'];
$newthreadid=$getnewestthreadforum['threadid'];

Replace 1 with the forumid of your choice.
Then, in the FORUMHOME template, put this wherever you want it:

Newest Thread in Forum forum name:
<a href="showthread.php?s=$session[sessionhash]&threadid=$newthreadid">$newthread</a>

That should work. If you get an invalid URL, try:
<a href=\"showthread.php?s=$session[sessionhash]&threadid=$newthreadid\">$newthread</a>
Instead of:
<a href="showthread.php?s=$session[sessionhash]&threadid=$newthreadid">$newthread</a>

Hope that helps.

remal
04-14-2003, 02:43 PM
not working :disappointed:



<?

$DB = mysql_connect("localhost", "SQLU_SER", "SQL_PASS");
mysql_select_db("SQL_DATABASE", $DB);

$numbersthreads= mysql_query("SELECT count(*) AS threads,max(threadid) AS maxthread FROM thread WHERE forumid=7 LIMIT 5");
$numberthreads= number_format($numbersthreads['threads']);
$getnewestthreadforum= mysql_query("SELECT threadid,title FROM thread WHERE threadid=$numbersthreads[maxthread] LIMIT 5");
$newthread=$getnewestthreadforum['title'];

mysql_close($DB);

echo "<a href=showthread.php?s=$session[sessionhash]&threadid=$newthreadid>$newthread</a>";
?>



it give me this output:
<a href=showthread.php?s=&threadid=></a>

The_Cyberdemon
04-14-2003, 04:37 PM
A: Make sure it's on the main page
B: Make sure you edited the *ForumRoot*/index.php page
C: Try putting \ in front of each quote

Oh, you messed up. Put the <a href... blah blah blah thing in your FORUMHOME template, not in the php file.

And do this: <a href=\"showthread.php?s=$session[sessionhash]&threadid=$newthreadid\">$newthread</a>

remal
04-14-2003, 05:07 PM
:)

but i dont want to put the results on the index.php

what im trying to do is creating a api.php script so other sites can get the latest threads from a the forum that they want:

ex: <? include "http://mysite.com/forum/api.php?forum=7&show=5"; ?>

which will show them the last 5 threads from forum 7

Highlander
04-18-2003, 07:14 PM
thats exactly what i searching for month :)

remal
04-18-2003, 07:52 PM
here its :)


api.php

<?
/// ex: http://www.you.com/api.php?fid=7
/// fid is the forum ID
/////////////// CONFIG ///////////////
//
$url = "http://www.you.com"; // URL to your board - NO TRAILING SLASH!
$urlimg = "http://www.you.com/images"; // URL to your board's images - NO TRAILING SLASH!
$maxthreads = "5"; // max threads to show. will show less if $last24 or $last7 limits it to less results than this number
$ob = "lastpost"; // set to one of the following: replycount , views , lastposter , title , lastpost (lastpost is most popular. it's the thread most recently replied to, then the second-to-last most recent, etc.)
$obdir = "desc"; // which direction to sort? "desc" goes from bottom to top (9 to 1, z to a, etc.). "asc" goes top to bottom (1 to 9, a to z, etc.). if you use lastpost for $ob, leave this set to desc or it will not work correctly!
$last24 = "0"; // 1 = last 24 hours; 0 = all (must set this to 0 if $last7 is set to 1)
$last7 = "0"; // 1 = last 7 days; 0 = all (must set this to 0 if $last24 is set to 1)
$bc1 = "#d8d8e9"; // first alt color
$bc2 = "#f0f0f7"; // second alt color
$hc = "#FFFFFF"; // head background color
$lc = "#000080"; // link color
$tc = "#FFFFFF"; // text color
$f = "tahoma"; // font face
$fs = "8"; // font size in points - 8 is normal, 6 is on the small side, 10 on the large side. play around with it. :)
$lastposter = "0"; // show last poster? 1 = yes; 0 = no
$views = "0"; // show view count? 1 = yes; 0 = no
$replies = "0"; // show reply count? 1 = yes; 0 = no
$lastpostdate = "0"; // show last post date and time? 1 = yes; 0 = no
$len = 35; // maximum number of characters of the title to show. e.g. if the title is 60 characters and this is set to 25, only the first 25 characters of the title will be shown (followed by ...)
$excludeforums = ""; // if you want to exclude a forum, put it's ID here. more than one, seperate them with commas, NO SPACES! e.g. 1,2,3,4
$includeforums = "$fid"; // if you only want to include certain forums, put their ids here. separate more than one with commas, NO SPACES! e.g. 1,2,3,4
$showmessages = "0"; // show the text of the last post too? 1 = yes; 0 = no
$lplen = "300"; // character length of last post text (if $showmessages is set to 0 this won't do anything).
$tw = ""; // width of the table that shows the info, in either a percent ( e.g. 95% ) or in pixels ( e.g. 300 ). leave blank if you want the table to be sized naturally
$showdate = "0"; // show the date, as well as the time? if the posts that show up in the list are likely to all be from today (or you set $last24 to "1"), you can set this to 0. if the posts are spread over multiple days, you probably want this set to 1.
$cs = "0"; // this is the cellspacing. 1 makes a thin line around the cells. 0 makes no line.
$showicon = "0"; // shows the posts' icon next to the post
$showforumtitle = "0"; // shows the forum title (linked to that forum) next to the thread title
$nb = "0"; // do you want breaks in text to appear as such? this may cause problems if there are large breaks in the text
//
///////////// END CONFIG /////////////


require("/full/path/to/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord) or die("Can't open connection to MySQL");
mysql_select_db($dbname) or die("Can't select database");

$hfs = $fs+2;
$fs .= "pt";
$hfs .= "pt";
if ($tw == "") {
$twt = "";
} else {
$twt = "width=\"$tw\"";
}
if ($cs == "") {
$cs = 0;
}

$wheresql = "WHERE thread.lastposter=user.username AND thread.open!='10'";

// we can't have both the last 24 hours *and* the last 7 days, so error out if needed
if ($last24 == "1" && $last7 == "1") {
print("Error: \$last24 and \$last7 are both set to 1. Please change one of them to 0.");
exit;
}
// otherwise we're gonna find out which one it is
// last 24
if ($last24 == "1") {
$time = time()-86400;
$wheresql .= " AND thread.lastpost>'$time'";
}
// last 7
if ($last7 == "1") {
$time = time()-604800;
$wheresql .= " AND thread.lastpost>'$time'";
}
// are we trying to exclude *and* include forums? if so, error out
if ($excludeforums != "" && $includeforums != "") {
print("Error: \$includeforums and \$excludeforums are both set with numbers. Please remove the numbers from <b>one</b> of these two to proceed.");
exit;
}
// otherwise figure out which one we're using
// include forums
if ($includeforums == "" or $includeforums <= "0") {
$quarter = "no";
} else {
$incfid = explode(",",$includeforums); $i = 0; $a = count($incfid);
if ($a > 1) {
$wheresql .= " AND (thread.forumid='$incfid[0]'";
++$i;
while ($i < $a) {
$wheresql .= " OR thread.forumid='$incfid[$i]'"; ++$i;
}
$wheresql .= ")";
} else {
$wheresql .= " AND thread.forumid='$incfid[$i]'";
}
}
// or exclude forums
if ($excludeforums == "" or $excludeforums <= "0") {
$quarter = "no";
} else {
$excfid = explode(",",$excludeforums); $i = 0; $a = count($excfid);
while ($i < $a) {
$wheresql .= " AND thread.forumid!='$excfid[$i]'"; ++$i;
}
}
if ($showforumtitle == "1") {
$ftitle = ",forum";
$fsel = ",forum.title AS ftitle";
$wheresql .= " AND thread.forumid=forum.forumid";
}
// ooh a query!
$query = "SELECT thread.lastpost,thread.title,thread.lastposter,thr ead.replycount,thread.views,user.userid,thread.thr eadid,thread.forumid$fsel,thread.iconid FROM thread,user$ftitle $wheresql ORDER BY thread.$ob $obdir LIMIT $maxthreads";
// let's get the info
$tr = mysql_query($query) or die("MySQL reported this error while trying to retreive the info: ".mysql_error());
$dtf = mysql_query("SELECT value FROM setting WHERE varname='dateformat' OR varname='timeformat' OR varname='timeoffset' ORDER BY varname");
$df = mysql_result($dtf,0,0);
$tf = mysql_result($dtf,1,0);
$tof = mysql_result($dtf,2,0);
if ($showdate == "1") {
$fdt = "$df $tf";
} else {
$fdt = "$tf";
}
$cols = 1;
// let's display the info
while ($threads = mysql_fetch_array($tr)) {
// are we going to show the message too?
if ($showmessages == "1") {
$query0 = "SELECT pagetext,postid,dateline,iconid FROM post WHERE threadid='$threads[threadid]' ORDER BY dateline DESC LIMIT 1";
$lastpost = mysql_query($query0) or die("MySQL reported this error while trying to retrieve the last post info: ".mysql_error());
while ($lastpost1 = mysql_fetch_array($lastpost)) {
$lastpostshort = $lastpost1[pagetext];
$postii = $lastpost1;
}
if (strlen($lastpostshort) > $lplen) {
$lastpostshort = substr($lastpostshort,0,$lplen);
$lastpostshort .= "...";
}
$smilies = mysql_query("SELECT smilietext,smiliepath FROM smilie");
while ($smiles = mysql_fetch_array($smilies)) {
$lastpostshort = str_replace($smiles[smilietext],"<img src=\"".$url."/".$smiles[smiliepath]."\" border=0>",$lastpostshort);
}
if ($nb == "1") {
$lastpostshort = nl2br($lastpostshort);
}
$lastpostshort = str_replace("[i]","<i>",$lastpostshort);
$lastpostshort = str_replace("","</i>",$lastpostshort);
$lastpostshort = str_replace("","<u>",$lastpostshort);
$lastpostshort = str_replace("","</u>",$lastpostshort);
$lastpostshort = str_replace("","<b>",$lastpostshort);
$lastpostshort = str_replace("","</b>",$lastpostshort);
$lastpostshort = str_replace("","<br>quote:<br><hr> ",$lastpostshort);
$lastpostshort = str_replace(""," <hr><br>\n",$lastpostshort);
$lastpostshort = str_replace("","<i>",$lastpostshort);
$lastpostshort = str_replace("","</i>",$lastpostshort);
$lastpostshort = str_replace("","<u>",$lastpostshort);
$lastpostshort = str_replace("","</u>",$lastpostshort);
$lastpostshort = str_replace("","<b>",$lastpostshort);
$lastpostshort = str_replace("","</b>",$lastpostshort);
$lastpostshort = str_replace("","<br>quote:<br><hr> ",$lastpostshort);
$lastpostshort = str_replace(""," <hr><br>\n",$lastpostshort);
$lastpostshort = str_replace("","<br>code:<br><hr> ",$lastpostshort);
$lastpostshort = str_replace(""," <hr><br>\n",$lastpostshort);
$lastpostshort = str_replace("","<br>code:<br><hr> ",$lastpostshort);
$lastpostshort = str_replace(""," <hr><br>\n",$lastpostshort);
$lastpostshort = str_replace("https://vborg.vbsupport.ru/","",$lastpostshort);
$lastpostshort = str_replace("https://vborg.vbsupport.ru/","",$lastpostshort);
$lastpostshort = str_replace("","",$lastpostshort);
$lastpostshort = str_replace("","",$lastpostshort);
$lastpostshort = str_replace("","",$lastpostshort);
$lastpostshort = str_replace("","",$lastpostshort);
}
// thanks to kier for this idea to do the alternating row colors
if (($counter++ % 2) != 0) {
$bc=$bc1;
} else {
$bc=$bc2;
}
// if the title is more than $len characters, we need to cut it off and add ... to the end
if (strlen($threads[title]) > $len) {
$title = substr($threads[title],0,$len);
$title .= "...";
} else {
$title = $threads[title];
}
// convert the date to a format readable by non-unix geeks :)
$fd = date($fdt,$threads[lastpost]);

echo("$title - $url/showthread.php?threadid=$threads[threadid]&ref=arabar.com\n");
// last poster column?



$fd = "";
}
?>