Nullified Posted August 16, 2012 Share Posted August 16, 2012 $articles = array(); $result = mysql_query("SELECT id, title, article, views, useful FROM tblknowledgebase ORDER BY useful DESC LIMIT 5"); while ($data = mysql_fetch_array($result)) { $data['urlfriendlytitle'] = str_replace(' ', '-', $data['title']); array_push($articles, $data); } $this->_tpl_vars['articles'] = $articles; The code works fine, but the line I am concerned about is $data['urlfriendlytitle'] = str_replace(' ', '-', $data['title']); Did I code it correctly so it will work or will i risk some problems with articles that have characters in the title that may need to be escaped? I don't know where or how WHMCS pulls {$article.urlfriendlytitle} from as it's not in the database table so I developed my own code. 0 Quote Link to comment Share on other sites More sharing options...
Nullified Posted August 16, 2012 Author Share Posted August 16, 2012 (edited) Update: What I need is the same function that WHMCS developers use so I can duplicate it on the homepage. I changed the mysql query to and it seems to be working: $result = mysql_query("SELECT id, title, article, views, useful, replace(replace(replace(replace(replace(replace(replace(title,' ','-'),'&','and'),'&','and'),',',''),';',''),'/','or'),'\\\\','') as urlfriendlytitle FROM tblknowledgebase ORDER BY views DESC LIMIT 5"); Edited August 16, 2012 by Nullified 0 Quote Link to comment Share on other sites More sharing options...
Nullified Posted August 17, 2012 Author Share Posted August 17, 2012 (edited) UPDATE: I got the code to acquire the category name for better seo, however I am having some htaccess rewriterule issues. If you would like to help please see this thread. {foreach key=num item=article from=$viewed} {php} $category = array(); $result = mysql_query("SELECT categoryid AS id FROM tblknowledgebaselinks WHERE articleid = '" . $this->_tpl_vars['article']['id'] ."'"); while ($cats = mysql_fetch_assoc($result)) { $category['id'] = $cats['id']; $result = mysql_query("SELECT name, replace(replace(replace(replace(replace(replace(replace(name,' ','-'),'&','and'),'&','and'),',',''),';',''),'/','or'),'\\\\','') as urlfriendlytitle FROM tblknowledgebasecats WHERE id = '" . $cats['id'] ."'"); while ($cats = mysql_fetch_assoc($result)) {$category['urlfriendlytitle'] = $cats['urlfriendlytitle'];} } $this->_tpl_vars['category'] = $category; {/php} <div align="left" class="kbarticle"><img src="images/article.gif" align="middle" alt="" border="0" /> <strong><a href="{if $seofriendlyurls}knowledgebase/{$article.id}/{$category.urlfriendlytitle|strtolower}/{$article.urlfriendlytitle|strtolower}.php?article={$article.id}{else}knowledgebase.php?action=displayarticle&id={$article.id}{/if}">{$article.title}</a></strong><span class="kbviews">{$LANG.knowledgebaseviews}: {$article.views}</span></div> {/foreach} Edited August 17, 2012 by Nullified 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.