Jump to content

Help needed please


liro

Recommended Posts

Hi,
I'm working with a cms called phpwcms and I'm stuck with a php script that I cannot seem to get working.
Please check my site [url=http://www.rklisse.nl]http://www.rklisse.nl[/url]. You will see part of the script on top of the page and what I have understand that it is a 'selfmade' problem. Only problem is I do not know how I did this and how to solve it.

Can you explain in simple english how this is caused and perhaps how to solve it.
More information on the script can be found at [url=http://www.phpwcms.de/forum/viewtopic.php?t=7261&highlight=artread]http://www.phpwcms.de/forum/viewtopic.php?t=7261&highlight=artread[/url]

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/26808-help-needed-please/
Share on other sites

This would be the script:
[code]<?PHP
// AUTHOR: Jens Zetterström {ART_READ}
// DESCRIPTION: Returns the number of times an article has been read.
// REQUIREMENTS: {MOST_READ} enhancement: phpwcms_article_read_count table, etc
// USAGE: {ART_READ:article_id:category_id}
//        I put it in my article template file so that
//        it appears for each article:
//        {ART_READ:<?php echo $GLOBALS["content"]["article_id"];?>:<?php echo $GLOBALS["content"]["cat_id"];?>}


function get_article_read_cnt($art_id, $cat_id, $dbcon)
{
  $count = 0;
   
  $sql ="SELECT count( article_id ) as art_cnt
          FROM ".DB_PREPEND."phpwcms_article_read_count
          WHERE article_id = $art_id
          AND cat_id = $cat_id ";

  if($result = mysql_query($sql, $dbcon))
  {
      $row = mysql_fetch_assoc($result);
      $count = $row["art_cnt"];
      mysql_free_result($result);
  }
  return $count;
}


// {ART_READ}
if( ! ( strpos($content["all"],'{ART_READ:')===false ) )
{
  $content["all"] = preg_replace('/\{ART_READ:(\d+):(\d+)\}/e','get_article_read_cnt($1,$2,$db);',$content["all"]);
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122597
Share on other sites

[quote]
// {ART_READ}
if( ! ( strpos($content["all"],'{ART_READ:')===false ) )
{
  $content["all"] = preg_replace('/\{ART_READ:(\d+):(\d+)\}/e','get_article_read_cnt($1,$2,$db);',$content["all"]);
}
[/quote]

I believe it is because of the single quotes around the 2nd param of the preg_replace function, also remove the semi-colon replace it with this

[code]
// {ART_READ}
if( ! ( strpos($content["all"],'{ART_READ:')===false ) )
{
  $content["all"] = preg_replace('/\{ART_READ:(\d+):(\d+)\}/e',get_article_read_cnt($1,$2,$db),$content["all"]);
}
[/code]

Hopefully thats it
Link to comment
https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122601
Share on other sites

OMG! lol. try replacing all of the code with this:

[code]
<?PHP
// AUTHOR: Jens Zetterström {ART_READ}
// DESCRIPTION: Returns the number of times an article has been read.
// REQUIREMENTS: {MOST_READ} enhancement: phpwcms_article_read_count table, etc
// USAGE: {ART_READ:article_id:category_id}
//        I put it in my article template file so that
//        it appears for each article:

function get_article_read_cnt($art_id, $cat_id, $dbcon)
{
  $count = 0;
   
  $sql ="SELECT count( article_id ) as art_cnt
          FROM ".DB_PREPEND."phpwcms_article_read_count
          WHERE article_id = $art_id
          AND cat_id = $cat_id ";

  if($result = mysql_query($sql, $dbcon))
  {
      $row = mysql_fetch_assoc($result);
      $count = $row["art_cnt"];
      mysql_free_result($result);
  }
  return $count;
}


// {ART_READ}
if( ! ( strpos($content["all"],'{ART_READ:')===false ) )
{
  $content["all"] = preg_replace('/\{ART_READ:(\d+):(\d+)\}/e',get_article_read_cnt($1,$2,$db),$content["all"]);
}
?>
[/code]

i removed that comment. i think it was screwing up your code.
Link to comment
https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122607
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.