Bradcrumb Script

I’m trying to create a breadcrumb script and so far I have

[php]
if(isset($id)) { $id = $id; } else { $id = 1; }
mysql_select_db($database_connection, $connection);
$query_destination = “SELECT * FROM destinations WHERE parent = ‘$id’”;
$destination = mysql_query($query_destination, $connection) or die(mysql_error());
$row_destination = mysql_fetch_assoc($destination);
$totalRows_destination = mysql_num_rows($destination);

$par=$row_destination[‘parent’];

mysql_select_db($database_connection, $connection);
$query_parent = “SELECT * FROM destinations WHERE id=’$par’”;
$parent = mysql_query($query_parent, $connection) or die(mysql_error());
$row_parent = mysql_fetch_assoc($parent);
$totalRows_parent = mysql_num_rows($parent);

?>

<?php echo $row_parent['name']; ?>

<?php do { ?>
<?php echo $row_destination['name'] ?>
<?php } while ($row_destination = mysql_fetch_assoc($destination)); ?>

[/php]

This is working ok but when you click in a link n the repeat its reloading the page and just changing the name in

<?php echo $row_parent['name']; ?>

to the parent, as its coded to do.

What i want to do is put the parents parent next to this if its possible.

how about:
[php]$parents=array();

$parent = mysql_query(‘SELECT * FROM destinations WHERE id=’.intval($id)) or die(mysql_error());
while($row_parent = mysql_fetch_assoc($parent))
{
array_unshift($parents,’<a href="?id=’.$row_parent[‘id’].’>’.htmlentities($row_parent[‘name’]).’’);

$parent = mysql_query(‘SELECT * FROM destinations WHERE id=’.intval($row_parent[‘parent’])) or die(mysql_error());
}

echo ‘

’ . implode(’ > ',$parents) . ‘

’;[/php]

maybe that is less complicated. on cause any seperator other than ’ > ’ may be used e.g. ‘

Been playing about with this one

[php]

<?php require_once('../Connections/connection.php'); if(isset($id)) { $id = $id; } else { $id = 1; } mysql_select_db($database_connection, $connection); $query_destination = "SELECT * FROM destinations WHERE parent = '$id'"; $destination = mysql_query($query_destination, $connection) or die(mysql_error()); $row_destination = mysql_fetch_assoc($destination); $totalRows_destination = mysql_num_rows($destination); $par=$row_destination['parent']; mysql_select_db($database_connection, $connection); $query_parent = "SELECT * FROM destinations WHERE id='$par'"; $parent = mysql_query($query_parent, $connection) or die(mysql_error()); $row_parent = mysql_fetch_assoc($parent); $totalRows_parent = mysql_num_rows($parent); ?> <?php if($_GET['path']) { $path = ($_GET['path']); } else { $path = 'Top/'; } $arIds = array (); $arSubPath = array (); $arPath = explode ('/', $path); $lastCat = $arPath[count ($arPath) - 1]; ?>
<?php echo 'All >'; if (count ($arPath) > 0) { for ($i = 0; $i < count ($arPath); $i++) { array_push ($arSubPath, $arPath[$i]);
if ($i == 0)
{
  $whereStr = 'parent = 0';
}
else
{
  $whereStr = "name LIKE '$arPath[$i]' AND parent = " . $arIds[count ($arIds) - 1];
}

$thisCat = mysql_query ("SELECT id, name FROM destinations WHERE $whereStr ");
if (mysql_num_rows ($thisCat) > 0)
{
  $row = mysql_fetch_assoc ($thisCat);
  array_push ($arIds, $row['id']);

  $subPath = implode ('/', $arSubPath);

  if ($i == 0)
  {
    $addStr .= $row['name'];
    $delStr .= $row['name'];
  }
  else
  {
    echo ' <a href="' . $thisPage . '?path=' . stripslashes($subPath) . '/">' . $row['name'] . "</a> >n";
  }

}

}

?>

<?php

$kids = mysql_query (“SELECT id, name FROM destinations WHERE parent = '” . $row[‘id’] . “’ ORDER BY name” );
if (mysql_num_rows ($kids) > 0)
{
while ($kidRow = mysql_fetch_assoc ($kids))
{
$thisID = $kidRow[‘id’];
$cCount = mysql_fetch_assoc (mysql_query ("SELECT children FROM destinations WHERE id = $thisID "));
$numKids = $cCount[‘children’];

  echo '<div style='width:150px; float:left'><a href="' . $thisPage . '?path=' . stripslashes($path) . $kidRow['name'] . '/">' . $kidRow['name'] . "</a></div>";
}

}
}
?>

[/php]

It works but is a bit long winded

Sponsor our Newsletter | Privacy Policy | Terms of Service