Page 1 of 2
comments data stored?
Posted: Sun May 07, 2006 8:15 am
by Dr.CSS
where is the data stored for the comments on a page?
if i add a comment to a page is there any way to connect to the data that stores the comments on that page and count the number of comments and ehco it to another page as a number such as Comments [ 12 ] ?
would this be a PHP or Tag?
mark
Re: comments data stored?
Posted: Sun May 07, 2006 1:47 pm
by calguy1000
The comments themselves are stored in a table..... so yes, you could write a tag or a plugin for extracting the number of comments for a page, but I don't know if the new comments module exports this data to smarty automatically for you.
Re: comments data stored?
Posted: Sun May 07, 2006 5:10 pm
by Dr.CSS
i obviously need to learn PHP,, any quick tips to that, and learn another language if i'm going to jump on other lang. forums here, saw one in french about a new design and ported it to CMSMS but can't help her without translater.
mark
Re: comments data stored?
Posted: Mon May 08, 2006 2:11 pm
by Elijah Lofgren
maksbud wrote:
where is the data stored for the comments on a page?
if i add a comment to a page is there any way to connect to the data that stores the comments on that page and count the number of comments and ehco it to another page as a number such as Comments [ 12 ] ?
would this be a PHP or Tag?
I just wrote a user defined tag that counts the number of comments on a news entry (new feature in CMSMS SVN and Comments SVN)
Here's the code for it:
Code: Select all
global $gCms;
$db = &$gCms->db;
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE page_id =".$params['thenewsid']." AND module_name='News' AND active='1'";
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
$num_rows = $dbresult->RecordCount();
echo $num_rows;
Here's how I call it from the News Summary Template:
Code: Select all
Number of comments: {count_news_comments thenewsid=$entry->id}
For a regular page something like this should work:
Code: Select all
global $gCms;
$db = &$gCms->db;
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE page_id =".$params['thenewsid'];
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
$num_rows = $dbresult->RecordCount();
echo $num_rows;
Re: comments data stored?
Posted: Mon May 08, 2006 5:56 pm
by Dr.CSS
cool

and i put this main code in a PHP, and that goes where?
do i change the,
page_id =".$params['
thenewsid']." AND module_name='
News' AND active='1'";
to comments?
was hoping to put it at the bottom of a content like
Comments [ 4 ] and you would clik on the word Comments and it would take you to a page where you could read/write comments.
mark
Re: comments data stored?
Posted: Mon May 08, 2006 7:47 pm
by Ted
The way that I got it working last night was having the comments module embedded into the detail view. At the bottom of the detail template, you put in the {cms_module module='comments' modulename='News' pageid=$entry->id} and it would show the list for that article. His plugin is just a little extension so that you can see the number on the summary tempate as well.
Re: comments data stored?
Posted: Tue May 09, 2006 1:35 am
by Dr.CSS
i still don't get it am i suposed to change this to something,,,
$params['
thenewsid']
is that param the '
content_id='65'', this is what i get when i edit the page,,
editcontent.php?content_id=65&page=1
i've put this in the 'content edit box' {cms_module module="komments"} and it shows up like a normal comments with "add a comment" and the comments made,
i changed it to 'komments' because i messed with the original and had to add a new Module by changing everything in the PHP including the Folder name, i really like the "mess" i made to the original template and can't add another template hence the 'new' Module,,
and how would i make it show up in these [ ] as a number,
i've got a redirect to the page, bottom of content has
Comments [ ] link to page that doesn't show in menu,, i just need to count the items on that page and echo it into those brackets
Comments [ 4 ]
thanks for any help

mark
Re: comments data stored?
Posted: Tue May 09, 2006 1:56 am
by Elijah Lofgren
maksbud wrote:
i still don't get it am i suposed to change this to something,,,
$params['thenewsid']
That actually holds the page id (or in my case the news id). You could change the name but you don't need to.
maksbud wrote:
is that param the '
content_id='65'', this is what i get when i edit the page,,
editcontent.php?content_id=65&page=1
i've put this in the 'content edit box' {cms_module module="komments"} and it shows up like a normal comments with "add a comment" and the comments made,
i changed it to 'komments' because i messed with the original and had to add a new Module by changing everything in the PHP including the Folder name, i really like the "mess" i made to the original template and can't add another template hence the 'new' Module,,
and how would i make it show up in these [ ] as a number,
i've got a redirect to the page, bottom of content has
Comments [ ] link to page that doesn't show in menu,, i just need to count the items on that page and echo it into those brackets
Comments [ 4 ]
thanks for any help

mark
Try something like this on the page that you're wanting to show the number of comments on:
Note (The thenewsid parameter is actually the id of the page with the comments on it. So if the id of the page with the comments on it is 65, pass 65 as the parameter).
Code: Select all
Comments: [ {count_news_comments thenewsid=65} ]
Re: comments data stored?
Posted: Tue May 09, 2006 1:57 am
by Dr.CSS
i've tried to make a tag out of that code and get this no matter if i put it in the edit page content or template, must be messing something up,,
Comments [{nocache:1fd63301dd53ba98789f3d4cbcf48072#0}DB error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Fatal error: Call to a member function on a non-object in /homepages/24/d151200904/htdocs/lib/content.functions.php(649) : eval()'d code on line 12
and a bunch of nocache errors all over the page other wise page shows up normal, put this in the template,,
Comments [{KommentCount}]
should i put {lieral} arond it?
mark
Re: comments data stored?
Posted: Tue May 09, 2006 2:03 am
by Dr.CSS

yes it worked!!!
Comments [{KommentCount thenewsid=65}]
YES YES
now it works as a blog right?
THANK YOU so much
mark
Re: comments data stored?
Posted: Tue May 09, 2006 4:46 am
by Dr.CSS
ok so what i need now is a way to make a new page on the fly when you clik the
Comments link ,,
you clik the link and it makes its own page with out having to have a page made aready like the "Add New Content" at the bottom of the "Content » Pages" in admin, and have a way to set the Default Template so it just gives them a page to add comments to,,
well you know what i mean

right?
i've got it set up to use the news module with a detail page template as summary and it shows all the news detail not summary, in newest to oldest order, but the
Comments [ 4 ] links to the same page for each 'news' article, don't want to add new
Comments page for each 'article' by hand hoping there is some way to make them on the fly,, not too much to ask is it?
thanks
mark
Re: comments data stored?
Posted: Tue May 09, 2006 2:42 pm
by Dr.CSS
now i get,,
--Add Me - module:Blog string:Comments-- [DB error: Unknown column 'module_name' in 'where clause'
Fatal error: Call to a member function on a non-object in /homepages/24/d151200904/htdocs/lib/content.functions.php(649) : eval()'d code on line 12
i took news and made it blog everything else works cept when i put the 'count' in, i made two U D Tags, one has,,
global $gCms;
$db = &$gCms->db;
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_komments WHERE page_id =".$params['theid'];
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
echo 'DB error: '. $db->ErrorMsg()."";
}
$num_rows = $dbresult->RecordCount();
echo $num_rows;
this first one works when i make the page and have [ {count theid=65} ] not the other one [ {blogcount theid=$entry->id} ],,
global $gCms;
$db = &$gCms->db;
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_komments WHERE page_id =".$params['theid']." AND module_name='Blog' AND active='1'";
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
echo 'DB error: '. $db->ErrorMsg()."";
}
$num_rows = $dbresult->RecordCount();
echo $num_rows;
ohwell
mark
Re: comments data stored?
Posted: Tue May 09, 2006 4:05 pm
by Elijah Lofgren
maksbud wrote:
now i get,,
--Add Me - module:Blog string:Comments-- [DB error: Unknown column 'module_name' in 'where clause'
Either you're not running the SVN version of the Comments module or you need to change:
maksbud wrote:
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_komments WHERE page_id =".$params['theid']." AND module_name='Blog' AND active='1'";
to:
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE page_id =".$params['theid']." AND module_name='Blog' AND active='1'";
And unless you really changed the name of the News module you'll want to use this instead:
// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE page_id =".$params['theid']." AND module_name='News' AND active='1'";
Re: comments data stored?
Posted: Tue May 09, 2006 6:41 pm
by Dr.CSS
made new modules, Blog, out of News,,
Komments, out of Comments, modified the original one of these as explained in earlier post,
now i get,,
--Add Me - module:Blog string:Comments-- 0 it counts now, i've looked thru all the 'Blog' PHP and i can't find anywhere else to --Add Me-- , but i can clik Comments and get taken to another page where it says add comment, but when i clik 'Add a Comment' it returns me to the original page, unable to add comment, still messing with the templates, about time i learn PHP.
mark

Re: comments data stored?
Posted: Tue May 09, 2006 8:04 pm
by Elijah Lofgren
maksbud wrote:
--Add Me - module:Blog string:Comments-- 0
it counts now, i've looked thru all the 'Blog' PHP and i can't find anywhere else to --Add Me-- ,
Weird. When I got an error like that it meant I needed to add a lang string to the language file for my module.
Try adding this to modules/Blog/lang/en_US.php and see if that error goes away:
maksbud wrote:
but i can clik Comments and get taken to another page where it says add comment, but when i clik 'Add a Comment' it returns me to the original page, unable to add comment, still messing with the templates, about time i learn PHP.
I think this may mean you need to use the SVN version of CMSMS (or 0.13 beta 3 if it comes out today).