boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Last 5 Comments
Goto page 1, 2  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Sat Jun 08, 2002 11:13 pm    Post subject: Last 5 Comments Reply with quote

Heya, all, I wrote a little hack that displays the last 5 comments posted to the blog and links to the post pages. I don't really know anything about PHP so it took me hours to find all the reference material but anyhow, thought someone else might be interested :)

At the very least, someone can tell me if I've messed things up royally and have endangered the very life on this planet with this silly little script :P

Here's the code or you can download it at http://files.nessahead.com/last5Comments.zip

Code:
<?php
   /* Last 5 Comments for b2 by [email protected]

   1. Change line 9 so that it points to your b2config.php file.
   2. Wherever you want it to display on your page, just put
      <?php include("path/to/last5Comments.php"); ?>
   3. Feel free to change it how you see fit & enjoy :) */

include("b2/b2config.php"); ?>

<p>
<?php
$db = mysql_connect("$dbhost", "$dbusername", "$dbpassword");
mysql_select_db("$dbname",$db);

$sql="SELECT comment_post_ID,comment_author,comment_date,comment_content FROM $tablecomments ORDER BY comment_date DESC LIMIT 5";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);
$cur = 1;

// Loop-dee-loop to display last 5 records
while ($num >= $cur) {

$row = mysql_fetch_array($result);

$comment_post_ID = $row["comment_post_ID"];
$comment_author = $row["comment_author"];
$comment_date = $row["comment_date"];

// Convert datetime to happiness
$string = $row["comment_date"];
$stringArray = explode("-", $string);
$date = mktime(0,0,0,$stringArray[1],$stringArray[2],$stringArray[0]);
$convertedDate = date("F jS", $date);

// Display each record
echo "<a href=\"index.php?p=$comment_post_ID&c=1#comments\">$comment_author - $convertedDate</a><br>";

$cur++;
}

?>
</p>

_________________
raar!


Last edited by nessahead on Tue Jun 11, 2002 7:31 pm; edited 4 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Sat Jun 08, 2002 11:14 pm    Post subject: Reply with quote

Oh, and you can see it in action on my sidebar at http://www.nessahead.com
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
kaiden



Joined: 20 Mar 2002
Posts: 43

PostPosted: Sun Jun 09, 2002 1:39 am    Post subject: Reply with quote

thats not bad. Unfortunately, I don't get many comments. ;)
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Sun Jun 09, 2002 1:53 am    Post subject: Reply with quote

Glad to hear it's not bad, then My first piece of code ever written not from a tutorial Razz
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
kaiden



Joined: 20 Mar 2002
Posts: 43

PostPosted: Sun Jun 09, 2002 2:28 am    Post subject: Reply with quote

Its always a good feeling of completion when you get a program done. I remember my first one. Ahhh, those were the days. very nice job indeed.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
achtungbaby



Joined: 21 May 2002
Posts: 27
Location: Los Angeles

PostPosted: Tue Jun 11, 2002 9:43 am    Post subject: Reply with quote

Very nice, thanks! Was wondering if anyone was ever going to write this up...unfortunately, I don't get too many comments either:(
_________________
Love your yellowworld.org
Back to top
View user's profile Send private message Send e-mail Visit poster's website
duegatti



Joined: 28 Jun 2002
Posts: 3

PostPosted: Fri Jun 28, 2002 5:59 pm    Post subject: how about the title of the post... Reply with quote

that the comment is attached to?
i have some people commenting on WAY old entries...and the only person that knows is me, because b2 emails me...it would help 'liven up' some old entries without having to adjust the timestamp to put it up front again, etc...
Back to top
View user's profile Send private message
.Chris



Joined: 30 Apr 2002
Posts: 186
Location: Hawaii

PostPosted: Sat Jul 06, 2002 12:16 am    Post subject: Subject instead of date? Reply with quote

First of all let me say I like this little hack and put off adding it until today.

I'd like to display the post subject in the place of the comment date. I've been trying to do it myself and get nothing but errors or nothing shows up at all. Can it just not be done or do I just not know how. (agrees with the later)

Help please.
Back to top
View user's profile Send private message Visit poster's website
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Sat Jul 06, 2002 8:55 am    Post subject: Reply with quote

Hrm, well, I'm tired so I can't fit my brain around it right now Sad Maybe someone else can step up?
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Benjy



Joined: 25 Jan 2002
Posts: 108
Location: Paris, France

PostPosted: Sun Jul 07, 2002 4:06 pm    Post subject: This might help .Chris Reply with quote

Code:
<?php include("b2/b2config.php"); ?>

<p>
<?php
$db = mysql_connect("$dbhost", "$dbusername", "$dbpassword");
mysql_select_db("$dbname",$db);

$sql="SELECT comment_post_ID,comment_author, post_title FROM $tablecomments, $tableposts WHERE comment_post_ID=ID ORDER BY comment_date DESC LIMIT 5";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);
$cur = 1;

// Loop-dee-loop to display last 5 records
while ($num >= $cur) {

$row = mysql_fetch_array($result);

$comment_post_ID = $row["comment_post_ID"];
$comment_author = $row["comment_author"];
$post_title = $row["post_title"];

// Display each record
echo "<a href=\"index.php?p=$comment_post_ID&c=1#comments\">$comment_author - $post_title</a><br>";

$cur++;
}

?>
</p>

Benjy.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Sun Jul 07, 2002 6:21 pm    Post subject: Reply with quote

See? Benjy is very cool Smile
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Benjy



Joined: 25 Jan 2002
Posts: 108
Location: Paris, France

PostPosted: Sun Jul 07, 2002 9:27 pm    Post subject: Reply with quote

Yes but I don't have much time to answer all the requests made here Sad
I haven't even installed b2 0.6pre3

Benjy.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
.Chris



Joined: 30 Apr 2002
Posts: 186
Location: Hawaii

PostPosted: Sun Jul 07, 2002 10:52 pm    Post subject: Reply with quote

Works great and I can see right where I messed up (in the loop)

Now I'm trying to get it to limit chars, as I have limited space where I put it.
Back to top
View user's profile Send private message Visit poster's website
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Mon Jul 08, 2002 7:28 am    Post subject: Reply with quote

This thread (http://www.tidakada.com/board/viewtopic.php?t=636) has info on limiting characters Smile
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Edlef



Joined: 16 Mar 2002
Posts: 71

PostPosted: Sat Jul 13, 2002 4:43 pm    Post subject: Great Reply with quote

Hi Nessahead,

your hack is great Very Happy I use the modified version with Author - Title on my testserver and it lokks good!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group