Firefox PHP

Hack to display last posts in another document

Posted by Rene 
Rene
Hack to display last posts in another document
February 27, 2001 03:17AM
The attached index.php will list the last 5 postings in forum number one..
I included this in index.php on my home page. It works just fine..

Modify it to fit your system..
There are a few comments in the attached file.

It's basically just a modified version of the quicklist script included with phorum.
Biggest difference is that it doesn't need an argument to be passed on to the php script.. It's included in the file.

If you wish to see it, it's on my front page. The site is in danish. (it's not an error ;)
[kraftwerk.adsl.dk]

Best regards..

Renˆ
I'm very keen to use this but can't download the attachment?

This is two scripts.
One for showing the 5 headlines
One for showing the last 5 text bodies (without carrige return)

Best regards
Rene


<?
//This script will show the last 5 posted headlines in forum number 1
$f=1;
chdir("../phorum/");
include "common.php";

$number=5; // number of messages to show.

$SQL="select id, thread, author, subject, datestamp from $ForumTableName order by datestamp desc limit $number";
$q->query($DB, $SQL);
$rec=$q->getrow();
while(is_array($rec)){
echo "$rec[author] -<a href=\"$forum_url/$read_page.$ext?f=$num&i=$rec[id]&t=$rec[thread]\"> $rec[subject] </a>- $rec[datestamp]<br>\n";
$rec=$q->getrow();
}
?>



<?

// this will show the last five posts in forum number 1.
// this will NOT do carrige returns, so the body text is returned as one line.
// I don't know what to do about it.

$f=1; // the forum number, as I only have one forum, I use number one
chdir("../phorum/"); // change this to fit your system
include "common.php";
$number=5; // number of messages to show.

$SQL="select id, body from $ForumTableName"."_bodies order by id desc limit $number";

$q->query($DB, $SQL);

$rec=$q->getrow();
while(is_array($rec)){
echo " $rec[body]<br>\n";
$rec=$q->getrow();
}
?>
Can we make the last 5 headers clickable to go directly to that particular message?
That would be an interesting feature...i really hope someone can include the code for that, as for i am a newbie in this area hehe

Jules
Clickable header? Aren't they linking to the particular message?

The line below is the output you see in your browser.
You can modify that as much as you want.

"$rec[author]" prints the name of the author who wrote the message.
It might look complex but it actually quite simple.
You can see the html codes in the line.

----- this line prints the html document ----
echo "$rec[author] -<a href=\"$forum_url/$read_page.$ext?f=$num&i=$rec[id]&t=$rec[thread]\"> $rec[subject] </a>- $rec[datestamp]<br>\n";


Best regards
René "rene AT kraftwerk.adsl.dk" (replace AT with @)

BTW: you can see this working on my site.
[kraftwerk.adsl.dk]
It's in danish so very few of you will be able to understand the site, but you can see the links on the main page. And you can click them to go to the message itself.
I just can't get this to work.
It'll be at [www.excellencethroughexercise.com]

The code I am using is:

<?
//This script will show the last 5 posted headlines in forum number 1
$f=1;
chdir("forum/");
include "common.php";

$number=5; // number of messages to show.

$SQL="select id, thread, author, subject, datestamp from $ForumTableName order by datestamp desc limit $number";
$q->query($DB, $SQL);
$rec=$q->getrow();
while(is_array($rec)){
echo "$rec[author] -<a href=\"$forum_url/$read_page.$ext?f=$num&i=$rec[id]&t=$rec[thread]\"> $rec[subject] </a>- $rec[datestamp]<br>\n";
$rec=$q->getrow();
}
?>

I tried getting rid of the $f=1; because I have about 50 forums, but that didn't work either. I just keep getting absolutely no html output. A blank page. No errors, which is good, but blank.

Any suggestions would be greatly appreciated!
Mick
Jules
last post including msg body...
May 08, 2001 03:30PM
Hi,
im trying to display on a separate page the headers plus the msg body of the 3 last messages of a certain forum...but i cant seem to get it to work since its 2 diferent tables...im having problems making the queries work with the while loop...any help would be appreciated =) thx

Jules
have you tried
SELECT
subject,
author,
email,
datestamp,
body
FROM
$ForumTableName,
$ForumTableName"."_bodies
WHERE
$ForumTableName.id=$ForumTableName"."_bodies.id $datelimit
AND
approved = 'Y'
ORDER BY
datestamp DESC
LIMIT
$ShowLimit";
Jules
Re: last post including msg body...
May 09, 2001 03:40AM
ya, tried something similar... i used your example, well, atleast now i dont get parse errors, but i also dont see anything hehe

here is what i did:


$f=8;
chdir("./forums");
require "common.php";
$number=3;
$ssSQL = "SELECT id, subject, author, host, datestamp, body FROM $ForumTableName, $ForumTableName"."_bodies WHERE $ForumTableName.id=$ForumTableName"."_bodies.id AND approved='Y' ORDER BY datestamp DESC LIMIT $number";

$q->query($DB, $ssSQL);
$res=$q->getrow();
while(is_array($res)) {

$date = $res["datestamp"];
$host = $res["host"];
$subject = $res["subject"];
$author = $res["author"];
$body = $rec["body"];

// html part
echo "$datestamp, $author, etc"

$res=$q->getrow();

}


i assume its not seeing an array, and thats why its not showing anything...what does that approved = 'Y' do?

thx
Jules
Jules
Re: last post including msg body...
May 15, 2001 02:25PM
Can anyone out there gimme a hand with this? I am not being able to make this work at all..i tried a lot of things and got lots of parse errors or no display at all...I need this working by friday the 18th or im doomed hehe i'd really appreciate it =)
thx for your attention...
Jules
what's your '//html part' exactly look like?
Jules
Re: last post including msg body...
May 15, 2001 07:19PM
i doubt its the html part but here it is:

echo "<div align=\"center\">";
echo "<table border=\"0\" width=\"90%\" cellspacing=\"5\">";
echo "<tr>";
echo "<td width=\"100%\" colspan=\"3\" bgcolor=\"#800080\"><b><font class=\"vb2\">$datestamp</font></b></td>";
echo "</tr>";
echo "<tr>";
echo "<blockquote>";
echo "<td bgcolor=\"#000000\" valign=\"top\" align=\"left\" width=\"100%\">";
echo "<font class=\"vw2\"><p>$subject</p></font>";
echo "<font class=\"text2\"><p>";
echo "$body";
echo "</p></font>";
echo "</td>";
echo "</blockquote>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"100%\" colspan=\"3\" bgcolor=\"#800080\"><p align=\"right\"><b><font class=\"vb1\">-- $author ($host)</font></b></td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo "<hr width=\"80%\" noshade size=\"1\" color=\"#800080\">";

i noticed i didnt put "$datelimit" in the select before the "AND"...think thats it?
thx
Jules
try to add your header.php and footer.php or include "html" part with a <body> tag. HTML showes up only info between <body> </body> tags.
Jules
Re: last post including msg body...
May 16, 2001 02:09AM
it does have the header and footer includes and they are working fine. somehow i think the while loop is not running because of the array....there is someting wrong with the select part i think...what you think?
ok, upload whole script then, i'll look at it.
Hi,
This scrip works just fine.

But how to cut long messages after X letters or after X words?
This is my final script in my site..
[www.ipoh1.f2s.com]

I've add the script to replace any word that longer than 15 characters..
eg:

hellohellohellohellohelloeh

will change to hellohellohello...
=)
so, when you display the new post, it won't mess up your table.
------------------------------------------------------------------------------------------------
$f=1; // the forum number, as I only have one forum, I use number one
chdir("phorum/"); // change this to fit your system
include "common.php";
$number=1; // number of messages to show.

$SQL="select id, thread, author, subject, datestamp from $ForumTableName order by datestamp desc limit $number";
$q->query($DB, $SQL);
$rec=$q->getrow();
while(is_array($rec)){
$subject = explode (" ", $rec[subject]);
$i = 0;
while($subject[$i]) {
if(strlen($subject[$i]) >= 15){ $subject[$i] = substr ($subject[$i], 0, 15)."..."; }
$i++;
}
$subject = implode (" ", $subject);
echo "<font size=\"1\">
Post by<b> $rec[author] </b><br>
<br>Subject :
<a href=\"$forum_url/$read_page.$ext?f=$num&i=$rec[id]&t=$rec[thread]\"> $subject </a><br>
<br>$rec[datestamp]<br></font>\n";
$rec=$q->getrow();
}
chdir("..");
-----------------------------------------------------------------------------------------------------------------------
// this will show the last five posts in forum number 1.
// this will NOT do carrige returns, so the body text is returned as one line.
// I don't know what to do about it.

Here is how you detect carriage return :)




$rec=$q->getrow();
while(is_array($rec)){
$postmsg = nl2br($rec[body]);
echo " $postmsg<br>\n";
$rec=$q->getrow();
The script works great, but I'm having trouble integrating it in a PHPnuke box, but have also tried to put it under each comment on the index file (where the forums are listed and described).

Could anyone modify this hack so that it would run on this page? That may also help me getting it to run anywhere else since the problem seems to be with this line:

  $q->query($DB, $SQL);
Sorry, you do not have permission to post/reply in this forum.