Splatgore Posted February 28, 2011 Share Posted February 28, 2011 Hi there, I've been tasked with the job of re-doing the company website from scratch and I'm having a bit of trouble with some of the logic involved as I'm not a web designer by trade. Or by any reasonable stretch of the imagination. Anywhoot, what I'm struggling with is this: I have laid out the website so for each of the core business units there is one php page, call it 'page x'. On page x there are two sections; a sidebar and a content section. At the top of page x there is a menu bar with a links to a different category (eg. services, products, about, contacts, etc). What I have at the moment for page x is an INCLUDE statement in each of the subsection which pulls through a html page and plops it down in the right place. What I am struggling with is how to use the links at the top of the page to pull through a different html page depending on what link I click. I was thinking that I could use something a couple of variables, $sidebar and $content, and then some kind of on-click function to pass a string to each of the variables and then use the INCLUDE statement to call the correct pages. What I have tentatively come up with is this : <a href=#><img src="/MS_Images/service_hlight.jpg" width="100" height="42" onclick=$sidebar = "OutsourceIT_Website/Managed Services/services_side.html" /></a> and then: <?php include $sidebar; ?> Would this work in principle? How do I go about making sure that the variable in the link is declared properly? Is there a better way to go about doing this that I am missing due to my ignorance? Hope someone can help because Uncle Google is getting fed up with my vague search terms. Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/ Share on other sites More sharing options...
KevinM1 Posted February 28, 2011 Share Posted February 28, 2011 Ooh boy, that's probably the exact opposite of what you should do. No website should rely on JavaScript for navigation. The solution, thankfully, is fairly simple, with some caveats for security/error handling. URLs can have query strings attached to them. Look at the URL for this page. It ends with 'index.php?topic=325844.0'. The part after the question mark is the query string. In PHP, you can grab them by using the $_GET superglobal array. Using our current page as an example, it would look like: <?php $topic = $_GET['topic']; ?> So, simply have your main navigation have links like companysite.com/index.php?p=about. Then, within your index.php, you could check to see if the page is set and include it: <?php $page = $_GET['p']; if(!empty($p)) { switch($p) { case 'About': include("about.html"); break; case 'News': include("news.html"); break; default: include("home.html"); // if the page doesn't match one of the pages you actually have, show the home content instead break; } } else { include("home.html"); // when no query string exists at all } ?> This is just a rough sketch, but should get you on your way. Look into .htaccess and mod_rewrite to make your URLs SEO friendly. Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1180977 Share on other sites More sharing options...
Splatgore Posted February 28, 2011 Author Share Posted February 28, 2011 Thank you so much for the speedy advice! I'll have a play with your ideas and see where I get. Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1180985 Share on other sites More sharing options...
Splatgore Posted March 1, 2011 Author Share Posted March 1, 2011 Thanks! This tip seems to be doing the job marvelously! One thing I didn't realise though was that PHP methods are case sensitive. I could have saved myself a couple of hours if I'd twigged to that sooner. Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1181030 Share on other sites More sharing options...
Muddy_Funster Posted March 1, 2011 Share Posted March 1, 2011 mark solved? Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1181158 Share on other sites More sharing options...
Splatgore Posted March 1, 2011 Author Share Posted March 1, 2011 I don't appear to be able to mark it as solved. Am I being blind? I don't see an option for it anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1181525 Share on other sites More sharing options...
redarrow Posted March 1, 2011 Share Posted March 1, 2011 this is to insucure , pretty sure there a better way? Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1181559 Share on other sites More sharing options...
Maq Posted March 1, 2011 Share Posted March 1, 2011 I don't appear to be able to mark it as solved. Am I being blind? I don't see an option for it anywhere. We just updated the forums so the "Thread Solved" mod hasn't been installed yet. Quote Link to comment https://forums.phpfreaks.com/topic/229181-calling-different-html-depending-on-which-link-is-clicked/#findComment-1181561 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.