Page 1 of 1

[Soloved] Error adding user defined tag

Posted: Mon Mar 16, 2009 6:47 pm
by klockej
I am trying to add a user defined tag for the comments module to count the number of comments. I have pulled the tag right from the wiki http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Content/Comments the tag is

Code: Select all

if(!isset(params['theid'])){
    die("Param: theid is required!");
}

global $gCms;

$db = &$gCms->db;

// Get number of comments
$q = "SELECT COUNT(comment_id) AS numrows FROM ".cms_db_prefix()."module_comments 
WHERE page_id = ? AND module_name='News' AND active='1'"; // or 'Uploads' or whatever instead of 'News'
$dbresult = $db->Execute( $q, array($params['theid']) );
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
else
{
    $num_rows_res = $dbresult->FetchRow();
    $num_rows = $num_rows_res['numrows'];
    ($num_rows == 1 ? $sing_plur = "comment" : $sing_plur = "comments");
    echo $num_rows." ".$sing_plur;
}
When I submit this i get the following error returned

Code: Select all

    * Invalid code entered.
    * Parse error: syntax error, unexpected '[', expecting T_PAAMAYIM_NEKUDOTAYIM in /home/jklockec/public_html/admin/adduserplugin.php(100) : eval()'d code on line 1 
Any help would be appreciated.

Re: Error adding user defined tag

Posted: Mon Mar 16, 2009 6:57 pm
by Nullig
Try this:

Code: Select all

global $gCms;

$db = &$gCms->db;

// Get number of comments
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE  page_id =".$params['theid'];
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
$num_rows = $dbresult->RecordCount();
echo $num_rows;
Nullig

[Solved] Error adding user defined tag

Posted: Mon Mar 16, 2009 7:03 pm
by klockej
Thanks ya that did it.

The Wiki may need to be updated.....

Re: [Soloved] Error adding user defined tag

Posted: Wed Dec 02, 2009 9:47 pm
by Pablillo
Hi. I know the issue is "solved", but try this:

Code: Select all

if(isset($params['theid'])){
    die("Param: theid is required!");
}
instead of this

Code: Select all

if(!isset(params['theid'])){
    die("Param: theid is required!");
}