On my single entry pages, php parsed on output, I’m pulling in ‘related entries’ with a php query. These are story reviews and recs- and I want to pull up entries with the same title (which is the story title) and all titles by the same author- author being a custom field {auth}, NOT the author of the article.
Works fine unless I have a ’ in the title. Now, I know this probably means I need to use stripslashes(), but I’m fuzy on how exactly I need to change the code. Here’s the relevant bit: (it’s inside a weblog tag)
?php
$myid= ‘{entry_id}’;
$mytitle= ‘{title}’;
$myauth= ‘{auth}’;
global $DB;
echo ‘<br><br><b>Related Entries:</b><ul>More entries on <i>’;
echo $mytitle;
echo ‘</i>’;
$sql = “SELECT title, weblog_id, url_title FROM exp_weblog_titles WHERE title = ‘$mytitle’ AND entry_id != $myid”;
$query = $DB->query($sql) or die (“Invalid query”);
foreach($query->result as $row) {
$title2 = $row[‘title’];
$weblog_id2 = $row[‘weblog_id’];
$url_title2 = $row[‘url_title’];
if ($title2 == ‘’)
{
echo ‘<li>None</li>’;
}
else
{
echo ‘<li>’;
echo $title2;
echo $url_title2;
echo ‘</li>’;
}
}
That’s the basic gist of it. Works fine as long as there are no special characters to escape- example - but not with a title like Life’s Aftermath.
Like I say, I pretty much know what the problem is, I’m just not dead sure how to fix it. I dinked around a bit, but thought I’d ask those who actually know what they’re doing. Any hints- greatly appreciated.
