scriptygoddess

13 Feb, 2003

Show recent comments WITH total comments from that comment author

Posted by: Jennifer In: Scripts

This is from another script request – Show most recent comments AND how many comments that person has made in total. Sort of a combination of this (Show most recent comments) and Girlie's comment leader script.

As shown on Girlie's blog, your connect.php file looks like this:

<?
// name of your database
$database = "database_name";
// connect to database
$db=mysql_connect ("localhost", "database_user", "database_password") or die ('I cannot connect to the database.');
mysql_select_db("$database",$db);
?>

Change the database_user, and the database_password as appropriate.

Then, this is the code that goes on your page: (Change the blog id as appropriate

<?
include ("/path/to/your/connect.php");
?>
<MTComments lastn="5" sort_order="descend">
<p>
<$MTCommentAuthorLink spam_protect="1" $>: <$MTCommentBody remove_html="1" trim_to="100"$>… [<a href="<$MTBlogArchiveURL$><$MTCommentEntryID pad="1"$>.php#<MTCommentID>">go</a>]<br>
(total comments:
<?
$qryCmt = sprintf("SELECT COUNT(*) as count FROM mt_comment WHERE comment_blog_id=1 AND comment_author='%s' AND comment_url='%s' AND comment_email='%s';",htmlentities ("<$MTCommentAuthor encode_php="qq"$>"), "<$MTCommentURL$>", "<$MTCommentEmail$>");
$reslt = mysql_query($qryCmt);
$rw = mysql_fetch_array($reslt );
echo $rw['count'];
?>)
</p>
</MTComments>

(little side note here – if you have a popular name, say like "Jennifer" 😉 – then you'll probably get a slightly inflated number… because it's just checking for the author's name – and it'll count anyone with the same "comment author" name)

17 Responses to "Show recent comments WITH total comments from that comment author"

1 | jade

February 16th, 2003 at 3:42 am

Avatar

To fix the common name problem, why not just add an extra bit to the SQL query to also compare the comment author's email address or URL? There may be a lot of Jennifers, but there is only one with your URL :)

2 | Donna

February 16th, 2003 at 12:48 pm

Avatar

Very cool – *this* was exactly what I was looking for! Thanks!

3 | Jennifer

February 16th, 2003 at 1:14 pm

Avatar

FYI – I updated the script (very minor change) because I noticed an error I was getting on my page…

4 | Jennifer

February 16th, 2003 at 1:38 pm

Avatar

Jade, I need to try that again. When I was first setting up the script I did that – and it wasn't working for some reason. (I got lazy and gave up – but I have to get back to it) – However, that still doesn't completely solve the problem – because, when I'm on my own blog (like I do here) I leave "email address" and "url" blank because my email can be found elsewhere on the site – and url… well, if you're on my blog, then I'm guessing you know the url) 😉 but that's still one step closer to being a more acurate number.

There are other people who have commented on my blog with the name Jennifer – but usually they also include a url OR email… (never having them BOTH blank like I do) – so maybe even better would be to have it check *both*

5 | Jennifer

February 16th, 2003 at 9:12 pm

Avatar

Ok – updated the code yet again. Added the check for email and url (so the number is more accurate) and fixed anoter bug that showed itself on my blog.

6 | heather

February 16th, 2003 at 11:23 pm

Avatar

I'm doing something wrong……keep getting this error – any advice?

(total comments:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/happypi/public_html/index.php on line 175)

7 | Lisa, Gal of Unix

February 16th, 2003 at 11:29 pm

Avatar

That was fun :) I really should dig up the schemas for MT and play around. I think SQL is a lot of fun.

8 | Asherah

September 9th, 2003 at 10:43 am

Avatar

I'm getting the same error that Heather mentioned. Help would be greatly appreciated, as i think this is a neat script!

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/eclipsedwitch.com/mt/blog/index.html on line 906

9 | mashby

September 25th, 2003 at 12:06 pm

Avatar

Jennifer,

I love this script! Thank you so much for making this so easy for us to add to our websites. I do have one question though.

Is there a version of this script that would allow you to use it with multiple weblogs within one install of MT? I have 4 on my site and would like the comment totals to reflect all the weblogs and not just the one webog that the visitor has commented in.

For example, if Joe posts a comment in the main weblog and one in the photos weblog, then his comment total is simply a (1) in each respective weblog. I'd prefer it if it showed a (2) since he made two comments, just one in each weblog.

Any tips, hints, or suggestions would be greatly appreciated and thanks again!

10 | The unknown sage

January 8th, 2004 at 11:58 am

Avatar

Error I'm getting: Build error in template 'Main Index': Error in <MTComments> tag: Error in <MTEntryLink> tag: You used an 'MTEntryLink' tag outside of the context of an entry; perhaps you mistakenly placed it outside of an 'MTEntries' container?

11 | Unix Gal

February 17th, 2003 at 12:30 am

Avatar

Busy Sunday
> Went out for breakfast > Washed my truck (thanks, hon!) > Grocery shopped > Installed SimpleComments (which shows your

12 | mashby.com

August 31st, 2003 at 7:36 pm

Avatar

Tweak City
I just can't seem to leave well enough alone. Every morning, after I post my entry, I have a tendency to tweak the site here and there. There's always a little something that needs to be added, nipped, or tucked.

13 | Bloggie Broad

September 14th, 2003 at 7:02 pm

Avatar

Bloggie's Scripty Scripts
Someone asked me which scripts I used to make all the cool things magically appear here on BB. I found nearly everything at Scriptygoddess –…

14 | Bloggie Broad

October 8th, 2003 at 12:43 am

Avatar

Reverb: Bloggie Scripty Fun
I'm organizing BB and deleted the posts revolving around my techie mess from earlier in the week, since it was an easy fix. I like…

15 | Bloggie Broad

November 23rd, 2003 at 5:49 pm

Avatar

Reverb: Bloggie Scripty Fun
I'm organizing BB and deleted the posts revolving around my techie mess from earlier in the week, since it was an easy fix. I like…

16 | Bloggie Broad

April 2nd, 2004 at 7:58 pm

Avatar

Random Comment Script Variation
This is a slight variation on the script used in…

17 | Code Novice

April 15th, 2004 at 12:50 am

Avatar

Random Comment Script Variation
This is a slight variation on the script used in…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements