This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Can't get comment count after the comments form is added.
#1

Hi. I'm preparing to use commentics on a website where I need to display the comment count under multiple articles (on the same page: Main page [ links to multiple other pages and comment counts next to each of these pages] ).

Here's what I do:

<?php
$id = "1"; //The ID of the page. You can get this from Manage -> Pages.
require_once ($_SERVER['DOCUMENT_ROOT'].'comments/includes/db/connect.php');
$query = mysql_query("SELECT * FROM `".$cmtx_mysql_table_prefix."comments` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysql_num_rows($query);
echo $total;
?>

It returns the count perfectly UNTIL the point where the comment form of the main page (the one that is used for these other links and for it's own content) is added.
<?php
$cmtx_page_id = '5';
$cmtx_reference = 'some page';
$cmtx_path = ($_SERVER['DOCUMENT_ROOT'].'comments/');
define('IN_COMMENTICS', 'true'); //no need to edit this line
require $cmtx_path . 'includes/commentics.php'; //no need to edit this line
?>


Then nothing is returned. I'm not very PHP savvy so I can just guess what's happening, but my guesses did not help so far...

Once again:

Main page----------------------------

some link with a comment count PHP code

some another link with a comment count PHP code

Commentics FORM PHP code

one more link with a comment count PHP code (but this time it doesn't return any value)

End of main page--------------------------


Do you have any idea of what's happening?
Reply
#2

Anyone? I really need to get this working.. ;/
Reply
#3

Hi,

Sorry for the late reply.

It's difficult to explain why but basically when you add that comment count code UNDER Commentics, you have to set the $cmtx_mysql_table_prefix variable.

So this should work:
PHP Code:
<?php
$cmtx_mysql_table_prefix
= '';
$id = "1"; //The ID of the page. You can get this from Manage -> Pages.
require_once ($_SERVER['DOCUMENT_ROOT'].'comments/includes/db/connect.php');
$query = mysql_query("SELECT * FROM `".$cmtx_mysql_table_prefix."comments` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysql_num_rows($query);
echo
$total;
?>

Have you completed the interview?
Reply
#4

Hi Steven, I was about to jump off my chair as this issue really bothered me a lot, but the $cmtx_mysql_table_prefix = ''; variable doesn't seem to be a fix for it Undecided .
I was about to write some script that would gather all the counts (which doesn't show up) into an array BEFORE the commentics is loaded and then load them from that array where I need them to be shown, but it's obviously quite a chunky/time consuming solution (as I'll have to refresh the Page ID's quite often, manually)..
Maybe you've tried that table_prefix and it worked for you? Maybe it's because my version is not the most recent (2.3)?

BTW - when I add the updated code - the error message about "database problem" dissapears, tho' it still doesn't return anything.
Reply
#5

I just installed Commentics v2.3 and I added the comment count code before and after Commentics.

As expected, I got an error with the 'below' comment count code:

Quote:Notice: Undefined variable: cmtx_mysql_table_prefix etc

.. and when I added the $cmtx_mysql_table_prefix = ''; it then worked.

Something that I had to do to get the 'above' comment count code to work was to add this line before it:

PHP Code:
<?php 
define
('IN_COMMENTICS', 'true'); //no need to edit this line

I assume you did this as well, otherwise it wouldn't have worked for you.

After I added that line, I removed the same line that was in the integration code to stop there from being a 'constant already defined' error.

Also I assume you have error reporting turned on (since you mentioned an error message disappearing).

Maybe try adding a line after the 'below' comment count code to make sure it's getting that far:

PHP Code:
<?php 
echo 'Is it getting to this stage?';

You could also see if the example.php file, which is included in the download package, works to make sure it's not related to your page.

Yeah the array idea sounds like it would work if all else fails.

Have you completed the interview?
Reply
#6

You've led me on the right way with this post above and I found a few DEFINE repeats which I missed earlier (quite some includes in different folders..) and at the same time I found out that one of the old scripts which I've left in the pages header (and didn't pay attention as I haven't used it for a while) was somehow interferring with that too (as it made a db connection every time page was loaded to collect the counts of visits for some other use I thought up earlier). But I don't need that code anymore so I just deleted it. Sum of all this - it's working afterall!
A big thank you, you've saved me quite a headache Steven. I'm lookin' forward to using this comments system on my projects as it seems like a high quality software so far.
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
29-Jul-2020, 08:34 AM
Last Post by MattyP
13-Apr-2020, 08:33 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)