[Soloved] Error adding user defined tag

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
klockej

[Soloved] Error adding user defined tag

Post 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.
Last edited by klockej on Mon Mar 16, 2009 7:37 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Error adding user defined tag

Post 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
klockej

[Solved] Error adding user defined tag

Post by klockej »

Thanks ya that did it.

The Wiki may need to be updated.....
User avatar
Pablillo
Forum Members
Forum Members
Posts: 36
Joined: Sat May 23, 2009 10:09 am

Re: [Soloved] Error adding user defined tag

Post 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!");
}
Haz el bien y aléjate del mal
Locked

Return to “CMSMS Core”