View previous topic :: View next topic |
Author |
Message |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Sat Jun 08, 2002 11:13 pm Post subject: Last 5 Comments |
|
|
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 |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
|
Back to top |
|
 |
kaiden
Joined: 20 Mar 2002 Posts: 43
|
Posted: Sun Jun 09, 2002 1:39 am Post subject: |
|
|
thats not bad. Unfortunately, I don't get many comments. ;) |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Sun Jun 09, 2002 1:53 am Post subject: |
|
|
Glad to hear it's not bad, then My first piece of code ever written not from a tutorial  _________________ raar! |
|
Back to top |
|
 |
kaiden
Joined: 20 Mar 2002 Posts: 43
|
Posted: Sun Jun 09, 2002 2:28 am Post subject: |
|
|
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 |
|
 |
achtungbaby
Joined: 21 May 2002 Posts: 27 Location: Los Angeles
|
Posted: Tue Jun 11, 2002 9:43 am Post subject: |
|
|
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 |
|
 |
duegatti
Joined: 28 Jun 2002 Posts: 3
|
Posted: Fri Jun 28, 2002 5:59 pm Post subject: how about the title of the post... |
|
|
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 |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Sat Jul 06, 2002 12:16 am Post subject: Subject instead of date? |
|
|
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 |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Sat Jul 06, 2002 8:55 am Post subject: |
|
|
Hrm, well, I'm tired so I can't fit my brain around it right now Maybe someone else can step up? _________________ raar! |
|
Back to top |
|
 |
Benjy
Joined: 25 Jan 2002 Posts: 108 Location: Paris, France
|
Posted: Sun Jul 07, 2002 4:06 pm Post subject: This might help .Chris |
|
|
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 |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Sun Jul 07, 2002 6:21 pm Post subject: |
|
|
See? Benjy is very cool  _________________ raar! |
|
Back to top |
|
 |
Benjy
Joined: 25 Jan 2002 Posts: 108 Location: Paris, France
|
Posted: Sun Jul 07, 2002 9:27 pm Post subject: |
|
|
Yes but I don't have much time to answer all the requests made here
I haven't even installed b2 0.6pre3
Benjy. |
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Sun Jul 07, 2002 10:52 pm Post subject: |
|
|
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 |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
|
Back to top |
|
 |
Edlef
Joined: 16 Mar 2002 Posts: 71
|
Posted: Sat Jul 13, 2002 4:43 pm Post subject: Great |
|
|
Hi Nessahead,
your hack is great I use the modified version with Author - Title on my testserver and it lokks good! |
|
Back to top |
|
 |
|