Bread crumbs navigation vs PDO

I’ve been using the following code to display bread crumbs-style navigation links. (I use the variables $TopnavName and $TopnavTable because the script is used by several websites and sections, which draw information from different tables.) I should also mention that all the preliminaries - $dsn, $opt and $pdo - are defined on a single file that’s include in every page on my site.

In this particular example, I’m viewing the URL MySite/Topics/Washington/Governor, where Washington/Governor is a value in the field URL, table px_topics.


$TopnavName = 'URL';
$TopnavTable = ''.$mysiteid.'_topics';

function get_path($node, $TopnavTable, $TopnavName) {

$result = mysql_query('SELECT Parent FROM ' . $TopnavTable . ' WHERE ' . $TopnavName . '="'.$node.'";');

   $row = mysql_fetch_array($result);
   $path = array();
   if ($row['Parent']!='') {
       $path[] = $row['Parent'];

$path = array_merge(get_path($row['Parent'], $TopnavTable, $TopnavName), $path);
   }
   return $path;
}

$mypath = get_path($MyURL, $TopnavTable, $TopnavName);
$MyLink = $mypath;
$MyDisplay = $mypath;
$MyD1 = array('K-2/', '3-5/', '6-8/', '9-12/', '_');
$MyD2 = array('', '', '', '', ' ');
$MyDisplay = str_replace($MyD1, $MyD2, $MyDisplay);
for($i=0;$i<count($mypath);$i++){
$TopNav = "<a href=\\"".$MyLink[$i]."\\"> ".$MyDisplay[$i]."</a>&nbsp;>";
$That = array('<a href="Topics">', '"> ', '>', '<a href="');
$This = array('<a href="/Topics/">', '">', '> ', '<a href="/Topics/');
$TopNav = str_replace($That, $This, $TopNav);
$TopNav = str_replace(''.$MyName.'/', '', $TopNav);
echo $TopNav;
}

echo '<span class="navhere">'.$Title.'</span>';

Now I’m trying to figure out how to convert this to PDO. I started out by changing the query to this…


function get_path($node, $TopnavTable, $TopnavName) {

 global $pdo;
 $stm = $pdo->prepare("SELECT Parent FROM :TNT WHERE :TNN = :Node");
 $stm->execute(array(
     'TNT'=>$TopnavTable,
     'TNN'=>$TopnavName,
     'Node'=>$node
));

I fixed the first error messages by adding adding the line “global $pdo,” but I now get this error message:

Call to a member function query() on a non-object

So I simplified my query to this…


function get_path($node, $TopnavTable, $TopnavName) {

 global $pdo;
 $stm = $pdo->prepare("SELECT Parent FROM 'px_topics' WHERE 'Washington/Governor' = :Node");
 $stm->execute(array(
     'Node'=>$node
));

But I get the same error message. So I’m guessing the problem is $node, but I don’t have a clue what to do with $node.


Can anyone tell me how to convert this script to PDO? Or, better yet, is there a simpler alternative for creating bread crumbs navigation links without all the confusing code? PDO is forcing me to change not just my queries, but everything related to them.

Thanks.

Mods: Is it possible to delete this thread? I messed up the question so bad, I need to start over. Thanks.