Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

PHP Breadcrumb Navigation

Is there an alternative 'simple' way to create the navigation trail below?  I'm having user permission problems with creating temporary tables.

The table structure is
nodeId, parentId, title
<?php

$id = $_REQUEST['id']; 

//Breadcrumb function
	function BreadcrumbRecordset($table, $id, $fk, $name, $get, $db, $conn) {
		mysql_select_db($db, $conn);
		
		// drop if exists
		$sql = "DROP TABLE IF EXISTS tmp_tbl";
		mysql_query($sql, $conn);

		// create tmp table
		$sql = "create temporary table tmp_tbl (KT_id int(11), $id VARCHAR(255), $name VARCHAR(255)) type=heap";
		mysql_query($sql, $conn) or die(mysql_error());
		
		// insert
		$getid = @$_GET[$get];
		$tmpid = 1;
		while($getid) {
			if (!is_numeric($getid)) {
				$getid="'$getid'";
			}
			$sql = "select $id, $fk, $name from $table where $id=$getid";
			$rs = mysql_query($sql, $conn) or die(mysql_error());
			$row_rs = mysql_fetch_assoc($rs) or die(mysql_error());
			if ($row_rs) {
				$nname = $row_rs[$name];
				$sql = "insert into tmp_tbl (KT_id, $id, $name) values ($tmpid, $getid, '$nname')";
				mysql_query($sql, $conn) or die(mysql_error());
			}
			$getid=$row_rs[$fk];
			mysql_free_result($rs);
			$tmpid++;
		}

		$sql = "select * from tmp_tbl order by KT_id desc";
		$ret = mysql_query($sql, $conn) or die(mysql_error());
		return $ret;
	}

$Breadcrumbs = BreadcrumbRecordset('tbl_Menu','nodeId','parentId','title','id',$database,$server);
$row_Breadcrumbs = mysql_fetch_assoc($Breadcrumbs);
$totalRows_Breadcrumbs = mysql_num_rows($Breadcrumbs);

?>

<!-- display breadcrumb trail -->
     <div id="breadcrumbs">
	   <a href="index.php?id=1" title="Home">Home</a>
          <?php do { ?>
          <?php if ($totalRows_Breadcrumbs > 0) { ?>
            &gt; <a href="index.php?id=<?php echo $row_Breadcrumbs['nodeId']; ?>" title="<?php echo $row_Breadcrumbs['title']; ?>"><?php echo $row_Breadcrumbs['title']; ?></a>
            <?php } ?>
          <?php } while ($row_Breadcrumbs = mysql_fetch_assoc($Breadcrumbs)); ?>
	   </div>The fo

Open in new window

0
studio1090
Asked:
studio1090
1 Solution
 
Ray PaseurCommented:
Looks like maybe your code snippet was cut off?  Anyway, one strategy for a breadcrumb navigation trail depends on having permanent tables.  The reason for this is that the temporary tables are lost when a script ends, so they are not very useful from page to page.

You can use GRANT to grant privileges for creating temporary tables.  See
http://dev.mysql.com/doc/refman/5.1/en/grant.html

Your hosting service should set this up for you in a jiffy.

The strategy I would follow for breadcrumbs would go something like this...

On every page do session_start()
record the timestamp, full URL and the session_id() in your DB table

The full URL is available by combining the protocol - check $_SERVER["SERVER_PROTOCOL"] - with the host and URI strings
$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

To show the path through the web site, SELECT from the table WHERE the session_id matches ORDER BY auto_increment key DESC.

To clean up this table and keep it from growing out of hand, DELETE FROM the table where the timestamp is older than a day or so.

HTH, ~Ray
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now