nuttycoder Posted August 7, 2007 Share Posted August 7, 2007 Hi i have a breadbrumb system working for my category's and sub category's using this code <?php $result = mysql_query("SELECT * FROM cats WHERE name='{$_GET['category']}'"); $info = mysql_fetch_array($result); $str = $info['name']; while ($info['parent_id'] != 0) { $info = mysql_fetch_array(mysql_query("SELECT * FROM cats WHERE id='".$info['parent_id']."'")); $str = $info['name']." > " .$str ; } echo "<p><a href=\"index.php\">Home</a>"; if (isset($str)) { echo " > $str </p>"; } else echo "</p> "; ?> here is my table scheme for my category's table `cats` ( `id` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL default '', `parent_id` int(11) NOT NULL default '0', PRIMARY KEY (`id`) and this is my table scheme for my tutorials tutorials` ( `tutorialID` int(4) NOT NULL auto_increment, `tutorialTitle` varchar(255) NOT NULL default '', `tutorialDesc` text, `tutorialCont` text, `category` varchar(40) NOT NULL default '', `tutorialDate` timestamp NOT NULL default CURRENT_TIMESTAMP, `tutorialviews` varchar(30) NOT NULL default '0', PRIMARY KEY (`tutorialID`) What i'd like is some advice how I would include pages into the breadcrumb for example as the code stands i can navigate to home > windows xp > email > but as soon as i click on a tutorial i lose the breadcrumb and just see home > as that part is static. I know i need to change how the code is laid out but not sure what i need to do any advice would be very useful cheers Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/ Share on other sites More sharing options...
nuttycoder Posted August 7, 2007 Author Share Posted August 7, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-317888 Share on other sites More sharing options...
Fadion Posted August 8, 2007 Share Posted August 8, 2007 when u click a tutorial u mess the breadcrumb maybe cos u loose the the url variable 'category' which is used in the query. Just guessing anyway. Also dont forget to clean your input data, as with your current code, one can inject code as much as he likes. $category = mysql_real_escape_string($_GET['category']); $result = mysql_query("SELECT * FROM cats WHERE name='$category'"); Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-318024 Share on other sites More sharing options...
nuttycoder Posted August 8, 2007 Author Share Posted August 8, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-318676 Share on other sites More sharing options...
nuttycoder Posted August 8, 2007 Author Share Posted August 8, 2007 any suggestions anyone? Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-318819 Share on other sites More sharing options...
Fadion Posted August 9, 2007 Share Posted August 9, 2007 Surely, saying "bump" every 2 posts doesnt help. U could consider my answer as even if it was pure bullsh** i was trying to help. Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-318971 Share on other sites More sharing options...
cmgmyr Posted August 9, 2007 Share Posted August 9, 2007 try this: <?php function crumbs($id, $level=0) { $sql = "SELECT parentid, name FROM cats WHERE id = $id"; $result = mysql_query($sql); list ($p, $n) = mysql_fetch_row($result); if ($p != '0') crumbs($p, $level+1); echo ($p == '0') ? "$n " : "» $n "; } ?> hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-319023 Share on other sites More sharing options...
nuttycoder Posted August 9, 2007 Author Share Posted August 9, 2007 Surely, saying "bump" every 2 posts doesnt help. U could consider my answer as even if it was pure bullsh** i was trying to help. Yes your right am sorry if I offended you it was not intended, I do need to clean my code I first want to try and find a solution to my problem then clean the code I tend to just create my sits then clean them up once they function probly not the best way to work :-\ Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-319150 Share on other sites More sharing options...
nuttycoder Posted August 9, 2007 Author Share Posted August 9, 2007 try this: <?php function crumbs($id, $level=0) { $sql = "SELECT parentid, name FROM cats WHERE id = $id"; $result = mysql_query($sql); list ($p, $n) = mysql_fetch_row($result); if ($p != '0') crumbs($p, $level+1); echo ($p == '0') ? "$n " : "» $n "; } ?> hope that helps thanks for that but am not sure that will work as the tutorials are in a table called tutorials and the cats table is just the actual category's, so when i click on a tutorial the breadcrumb code doesen't know where I am I think relate the tutorials with the categorys but in a way they already are as when you click on a category you see all tutorials for that category. Quote Link to comment https://forums.phpfreaks.com/topic/63770-breadcrumb-page-from-category/#findComment-319161 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.