designer76 Posted May 9, 2010 Share Posted May 9, 2010 I need some help with how my dynamic page urls are displaying/working. In the example below, lets say that I always want type to display the same thing in my URL even in my sections and sub-sections, how would I go about doing that? In other words, if I click a main link, my url reads like this: http://localhost/index.php?type=clocks, which is fine. Now, when I click on a section link, the whole thing has to change to: http://localhost/index.php?category=clocks&type=gold in order for the link to work correctly. I want the type to always remain the same and then the category to change. So I want it to be like this: http://localhost/index.php?category=gold&type=clocks, or http://localhost/index.php?category=silver&type=clocks, and so on. How do I go about fixing this? In the third piece of code below you will see that in order for the link to work correctly, watch can no longer be equal to type, it has to be equal to category, which is not what I want. I want whatever is in the type to always remain the same. So I could have http://localhost/index.php?category=gold&type=watch&item=mens_swiss_watch. With the example link I just provided, you can add as many things as you want to the link, but type is always equal to watch, category is always equal to gold (or silver or whatever) and item is always equal to the specific item. It's not like that now when I start getting in to using sections and sub-sections. INDEX FILE: include ('header.php'); $type = $_GET['type']; $category = $_GET['category']; $item = $_GET['item']; if (!$type) $type = "landing"; if (!$category) $category = "types"; if (!$item) $path = "$category/".$type.".php"; else $path = "$category/$item/".$type.".php"; include ($path); include ('footer.php'); HEADER: //////////////////////HEAD INFO////////////////////////////// Doctype, keywords, meta data and all of that goes here. //////////////////////END HEAD INFO////////////////////////// <body> <div class="navigation"> <ul> <li class="watch"><a id="wacthId" href='index.php?type=watches' title="Watches">watch link</a> <li class="clock"><a id="clockId" href='index.php?type=clocks' title="Clocks">clock link</a> <li class="belt"><a id="beltId" href='index.php?type=belts' title="Belts">belt link</a> </ul> </div> PEOPLE CLICK ON THE WATCH LINK AND GO TO THIS PAGE, WITH ADDITIONAL NAVIGATION FOR WATCHES: <div class="watch_navigation"> <ul> <li class="gold_watch"><a id="gold_watchId" href='index.php?category=watch&type=gold' title="Gold Watch">gold link</a> <li class="silver_watch"><a id="silver_watchId" href='index.php?category=watch&type=silver' title="Silver Watch">silver link</a> <li class="bronze_watch"><a id="bronze_watchId" href='index.php?category=watch&type=bronze' title="Bronze Watch">bronze link</a> </ul> </div> Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/ Share on other sites More sharing options...
Joshua4550 Posted May 10, 2010 Share Posted May 10, 2010 I only read it briefly, but from what I understand, firstly you wanted.. $type = $_GET['type']; // Clocks $category = $_GET['category']; // Gold echo '<a href="index.php?category=silver&type=' . $type . '">click to watch silver</a>'; Am i right in that's one of what you wanted? Say they first visited index.php?category=gold&type=clocks Then the link in the code i showed u would send them to index.php?category=silver&type=clocks Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1055581 Share on other sites More sharing options...
designer76 Posted May 10, 2010 Author Share Posted May 10, 2010 I apologize, I probably didn't word my problem 100% correctly. I can make the link display however I want it to, the issue is that the link won't physically work because the code must be in some kind of order and sequence. That's why I have to move whatever type equals over to the category part (when I start using sections and sub-sections), so basically Joshua4550s url example will LOOK how I want it to, but it won't function properly. This is what I am trying to figure out, why the type must change to the category once I start using sections (and sub-sections) in order for the link to work. I don't know if my folder structure needs to change or whether it's my code. Here is the best link I could find showing what I mean: http://www.rocawear.com/nshop/product.php?view=listing&dept=men&groupName=NewArrivalsMens No matter what category you click in the left navigation, the department is always equal to men, only the groupName= changes based upon which link you click in the left nav. That's what I'm trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1055759 Share on other sites More sharing options...
Muddy_Funster Posted May 10, 2010 Share Posted May 10, 2010 Looks to me like you are using <div>'s where you should be using arrays. Try converting your code to use arrays to store the info and see how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1055773 Share on other sites More sharing options...
designer76 Posted May 10, 2010 Author Share Posted May 10, 2010 Looks to me like you are using <div>'s where you should be using arrays. Try converting your code to use arrays to store the info and see how it goes. I'm not sure exactly what you mean or how I should go about that. Would you be able to go in to detail/explain further? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1055782 Share on other sites More sharing options...
designer76 Posted May 10, 2010 Author Share Posted May 10, 2010 Can anybody provide any further insight on this? Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1056082 Share on other sites More sharing options...
Muddy_Funster Posted May 11, 2010 Share Posted May 11, 2010 Because you are running the full URL header in the <div> it isn't very flexable. Which is probably what is throwing you when you try to add another level of complexity. Think about assigning the header values first to either a series of page specific variables or, better still, a couple of arrays. then call the array values in the <div> list links. This lets you assign the appropriate page per link sub level much more effectivly. $catagory = array("watch" => "?catagory='watch'", "clock" => "?catagory='clock'"); $type = array("gold" => "&type='gold'", "silver" => "&type='silver'", "watch" => "?type='watch'", "clock" => "?type='clock'"); Using arrays like this lets you set your list links refferentialy: <div class="navigation"> <ul> <li class="watch"><a id="wacthId" href='index.php<?php echo $type['watch']; ?>' title ="Watches">watch link</a> <li class="clock"><a id="clockId" href='index.php<?php echo $type['clock']; ?>' title="Clocks">clock link</a> ... ... <li class="gold_watch"><a id="gold_watchId" href='index.php<?php echo $catagory['watch'].$type['gold']; ?>' title="Gold Watch">gold link</a> </div> does that help any? Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1056281 Share on other sites More sharing options...
designer76 Posted May 11, 2010 Author Share Posted May 11, 2010 Sorry for the late reply Muddy_Funster. I apologize, but I may have been leaving out an important element that I didn't think about at the time. Someone who looked at my code on another site said that the reason why I am having problems is because I am using an actual folder structure on my site. They said that dynamic pages were made for pulling all of your info from a MYSQL database and not from folders on your local site. They are saying that I can't have my url read the way I want it to because you aren't supposed to use dynamic pages without pulling the info from a MYSQL database. I guess what I don't understand is that there are videos like these: where people do it the way that I do using folders, so I thought that there was a way to make it work. I'm not sure if it is about changing my folder structure or if it's just impossible altogether. Also, just to be clear about the problem, When I physically make my link look like this, it works fine and goes to the page that it's supposed to. href='index.php?type=watches' It's when I get in to using sections and subsections that my type must equal gold (or silver, or whatever) and can't stay equal to watches. If I try to switch the link around, then I just get a blank white screen. What The Link Must Look Like In Order To Work: href='index.php?category=watch&type=gold' What I Want The Link To Look Like, But It Gives Me A White Screen: href='index.php?category=gold&type=watches' Here Is An Example Of The Folder Structure On My Site: Root Directory: index.php, watches (folder), clocks (folder) & types (folder). Files inside types folder: home.php, watches.php, clocks.php Folders inside clocks & watches folders: gold, silver, bronze Files inside gold, silver & bronze folders: mens_american_gold_watch.php, mens_british_gold_watch.php, mens_american_silver_watch.php, etc... INDEX FILE Showing how code is getting files: include ('header.php'); $type = $_GET['type']; $category = $_GET['category']; $item = $_GET['item']; if (!$type) $type = "landing"; if (!$category) $category = "types"; if (!$item) $path = "$category/".$type.".php"; else $path = "$category/$item/".$type.".php"; Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1056798 Share on other sites More sharing options...
Muddy_Funster Posted May 12, 2010 Share Posted May 12, 2010 ... another site said that the reason why I am having problems is because I am using an actual folder structure on my site. They said that dynamic pages were made for pulling all of your info from a MYSQL database and not from folders on your local site. They are saying that I can't have my url read the way I want it to because you aren't supposed to use dynamic pages without pulling the info from a MYSQL database.... just as well you found this site then, where people actualy know what they are talking about! it makes no difference to php where it gets the information from, so long as there is information to get - there is code that will get it. It may be that you need to tweek how you set your $path if the pages arn't loading from with the folders but there is no restriction in php regards loading flat files from the server. Did you try using the arrays as I sugested? Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1057062 Share on other sites More sharing options...
designer76 Posted May 12, 2010 Author Share Posted May 12, 2010 I'm not sure the array will fix my problem, I think it's exactly what you said in that my path/folder structure needs to be laid out differently. The way I have it laid out now, I'm not sure that when I make my links read how I want them to that the path is leading it in the right direction. I'm just not sure how to re-work my path and folder structure to get things to work how I want them to. Quote Link to comment https://forums.phpfreaks.com/topic/201204-need-some-help-with-dynamic-page-urls/#findComment-1057342 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.