UrbanDweller Posted May 16, 2012 Share Posted May 16, 2012 Hey, I'm currently planning on how i will code some breadcrumbs for a shopping site where the admin can add more options/levels to the database which in turn store products. I understand how to get the url of the previous options/level but am stuck on retrieving the name of the level and can only imagine retrieving it from the database. Though Its possible to do so is there any other method as relying on the database for crumbs seems like a easy way out or am i just picky? the typical url is like so: website.com/shop.php?cat_id=1004, so i cant retrieve the name from it unless i cross reference it to its database name and dont know how to retreive from their <a href> tag. On a side note is there a graph that can show a general outline of how many db queries a server can make per second etc depending on its hardware? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/ Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 You could always cache all your category data (using Memcache or similar), and retrieve all categories on every page load. That'll ensure maximum performance with less trips to the DB. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1345773 Share on other sites More sharing options...
UrbanDweller Posted May 16, 2012 Author Share Posted May 16, 2012 Yeah i have always thought about caching but my knowledge isnt ready to start diving into new areas like that yet as my customer base isnt large enough nor is my coding skills. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1345779 Share on other sites More sharing options...
UrbanDweller Posted May 16, 2012 Author Share Posted May 16, 2012 Sorry for double post but, is $_SERVER["HTTP_REFERER"} safe to use to get previous page link for my crumbs as ive heard a lot about it being untrustworthy or is that just external urls? Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1345811 Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 You could use the referrer to know where the user came from, or better, you could store every page viewed in an array in the $_SESSION (to maintain a chain). But that chain has nothing to do with breadcrumbs, which should be a hierarchical representation of where the user is in your site (e.g. Home -> Parent -> Child -> Grandchild Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1345813 Share on other sites More sharing options...
Jessica Posted May 16, 2012 Share Posted May 16, 2012 Breadcrumbs can also refer to the steps the user took to get to that page, a history like you'd see in the drop-down of your back bar. It isn't always the category structure. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1346038 Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 Breadcrumbs can also refer to the steps the user took to get to that page, a history like you'd see in the drop-down of your back bar. It isn't always the category structure. Well sure you could do history crumbs, but they're useless and confusing (you're basically just mimicking browser.back() functionality, which is why 99.999% of websites that have crumbs do heirarchical crumbs and not historical crumbs. I'm sure you're not suggesting that the OP go with his original intent of crumbing the history... it's a bad idea. Jakob Nielsen has my back on this one: http://www.useit.com/alertbox/breadcrumbs.html Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1346071 Share on other sites More sharing options...
Jessica Posted May 16, 2012 Share Posted May 16, 2012 I'm simply saying it is one option, and based on what the OP has said, it is the option he is trying to use. Otherwise why ask about the $_SERVER["HTTP_REFERER"} for previous page link? I agree that it's more useful to have it as hierarchy. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1346082 Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 Gotcha... but just because he wants it doesn't mean he understands what he's asking for. Helping people means more than just giving them what they ask for... it also has to do with understanding what they want / need, and guiding them in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1346085 Share on other sites More sharing options...
UrbanDweller Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks for the input the main issue was retrieving the previous category name which I had to use the database as I found was the best/easiset solution for my dynamic page as the admin could add more and more categories. So i worked back from the current page via the category parent id all the way to home page which seems to have worked perfectly. I dropped the refeerer idea to as its too risky to create crumb urls Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1346173 Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 FYI, if you have a recursive DB structure (parent_id referencing same table), you should use a creative series of LEFT JOINs to pull out your entire heirarchy in one query. Quote Link to comment https://forums.phpfreaks.com/topic/262585-dynamic-breadcrumbs-should-i-use-database/#findComment-1346176 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.