liro Posted November 10, 2006 Share Posted November 10, 2006 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 More sharing options...
JasonLewis Posted November 10, 2006 Share Posted November 10, 2006 well it would help if you posted a bit of the script above that. i have a feeling you are either echoing it by mistake or you are closing your php tag. Link to comment https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122596 Share on other sites More sharing options...
liro Posted November 10, 2006 Author Share Posted November 10, 2006 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 More sharing options...
FSGr33n Posted November 10, 2006 Share Posted November 10, 2006 [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 More sharing options...
liro Posted November 10, 2006 Author Share Posted November 10, 2006 Nope, sorry. Still the code is on top of my page. Link to comment https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122605 Share on other sites More sharing options...
JasonLewis Posted November 10, 2006 Share Posted November 10, 2006 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 More sharing options...
liro Posted November 10, 2006 Author Share Posted November 10, 2006 No sorry again, site went blank completely now!!!!!! :'( Link to comment https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122609 Share on other sites More sharing options...
liro Posted November 10, 2006 Author Share Posted November 10, 2006 Hi, solved!!!!!!From the original code the following line needed to be removed to get it work!// {ART_READ:<?php echo $GLOBALS["content"]["article_id"];?>:<?php echo $GLOBALS["content"]["cat_id"];?>} Thanks to you all! Link to comment https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122625 Share on other sites More sharing options...
JasonLewis Posted November 11, 2006 Share Posted November 11, 2006 but thats the comment that i removed. and i added that bit in that FSGrr3n added. Link to comment https://forums.phpfreaks.com/topic/26808-help-needed-please/#findComment-122937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.