fallingintoZero Posted April 25, 2008 Share Posted April 25, 2008 i've been scowering the internet, and serching this forum, and can't seem to find any tutorials on how to create variable links. maybe i am not searching the right words or phrases, but i'm at a loss. i am trying to make different links based off an index.php page. all the pages are generally the same, but display different content. the body of the index.php page is pretty simple and ran off includes: <body> <div id="page"> <?php include ('header.php') ?> <div id="wrapper" class="clearfix"> <div id="content" class="widecolumn"> <h2 class="title">Home (n.)</h2> <?php include ('index_content.php') ?> </div> <?php include ('sidebar.php') ?> </div> <?php include ('footer.php') ?> </div> </body> each other page is pretty much the same, for example, contact.php is: <body> <div id="page"> <?php include ('header.php') ?> <div id="wrapper" class="clearfix"> <div id="content" class="widecolumn"> <h2 class="title">Contact (n.)</h2> <?php include ('contact_content.php') ?> </div> <?php include ('sidebar.php') ?> </div> <?php include ('footer.php') ?> </div> each page has the same includes, one of which is sidebar.php, which is the navigation menu. <div id="sidebar"> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <style type="text/css"> <!-- .style3 {color: #d8d7d3} --> </style> <h3>Main Menu</h3> <ul class="style3"> <li><a href="index.php">home.</a></li> <li><a href="about.php">about.</a></li> <li><a href="external.php">external.</a></li> <li><a href="contact.php">contact.</a></li> </ul> </body> </html> </div> as you see, each link is it's own file. about.php, external.php, contact.php, etc. i'd like to make the links variable links so the addresses would be something like index.php?page=about, index.php?page=external, so forth so forth... and the content would display in the div tags, rather then seperate pages, with seperate includes to where the content is. also, i'm trying to set a flash intro to also be index.php, so i'd be setting the current index.php to index.php?page=home. can anyone give some advice or direction as to how i would go about doing this? Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/ Share on other sites More sharing options...
DeanWhitehouse Posted April 25, 2008 Share Posted April 25, 2008 you use IF Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527467 Share on other sites More sharing options...
fallingintoZero Posted April 25, 2008 Author Share Posted April 25, 2008 you use IF can you elaborate? i'm not sure what you mean by that ??? Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527469 Share on other sites More sharing options...
teng84 Posted April 25, 2008 Share Posted April 25, 2008 you can try this... <?php if(isset($_GET['page'])){ switch($_GET['page']){ case'home': include'home.php'; break; case'external': include'external.php' break; case'ect........': //stuff here break; default: include'home.php'; } } or this if(isset($_GET['page'])){ switch($_GET['page']){ case'home': //stuff here case'external': //stuff here case'ect........': //stuff here break; default: include'home.php'; } } ?> hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527471 Share on other sites More sharing options...
fallingintoZero Posted April 25, 2008 Author Share Posted April 25, 2008 you can try this... (code removed) hope that helps thank you very much. do i put this inside where the include tag currently is? Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527473 Share on other sites More sharing options...
teng84 Posted April 25, 2008 Share Posted April 25, 2008 sorry im lost ... if you are going to use the first sample you have to create a separate pages for home.php external.php and include them like i did.. if you are going to use sample number to create a page where it has all the data to be loaded and divide them according to each cases eg.. case home put the date for home on that case case 'home': your code here that will out output the data's from home Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527478 Share on other sites More sharing options...
fallingintoZero Posted April 25, 2008 Author Share Posted April 25, 2008 i think i did something wrong Parse error: syntax error, unexpected T_BREAK in /home/redeemed/public_html/test/index2.php on line 31 edit: i'm using the first method Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527487 Share on other sites More sharing options...
teng84 Posted April 25, 2008 Share Posted April 25, 2008 maybe you missed the terminator ; include'external.php' ; my bad sorry about that .. Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527492 Share on other sites More sharing options...
fallingintoZero Posted April 26, 2008 Author Share Posted April 26, 2008 maybe you missed the terminator ; include'external.php' ; my bad sorry about that .. i should have noticed that myself lol. okay, everything pretty much works perfectly. the only problem is the default content isn't loading. the default and home content is the same, and are both linked the same. but if i just go to index2.php, nothing shows up. it's all blank. but if i click home, the content shows up. <div id="wrapper" class="clearfix"> <div id="content" class="widecolumn"> <?php if(isset($_GET['page'])){ switch($_GET['page']){ case'home': include'index_content.php'; break; case'external': include'external_content.php'; break; case'about': include'about_content.php'; break; default: include'index_content.php'; } } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527498 Share on other sites More sharing options...
teng84 Posted April 26, 2008 Share Posted April 26, 2008 not sure about your second problem but this will not cater index2.php because this condition is dedicated to that page which is index.php Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527501 Share on other sites More sharing options...
fallingintoZero Posted April 26, 2008 Author Share Posted April 26, 2008 hmm. well i just switched everything over to be index.php, and same thing. it seems like it's not recognizing anything to be the default content. any idea if there's any work around? edit: should the default be set as a require rather then an include? edit2: ignore that. it didn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527504 Share on other sites More sharing options...
teng84 Posted April 26, 2008 Share Posted April 26, 2008 try to look at your query string .... see the url and paste here Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527513 Share on other sites More sharing options...
fallingintoZero Posted April 26, 2008 Author Share Posted April 26, 2008 try to look at your query string .... see the url and paste here i'm not sure what you mean. sorry, i feel kinda stupid right about now lol i also just realized that i didn't really explain things right. i didn't mean to say nothing shows up. i meant to say the content of index_content.php doesn't show up. http://www.redeemedplaces.com/test is where i'm running the test index.php, if you wanted to see what i mean. content doesn't show up by default. i have to click home for it to display Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527514 Share on other sites More sharing options...
fallingintoZero Posted April 26, 2008 Author Share Posted April 26, 2008 wow. ignore that. i really am an idiot. i just realized, there was no "else" statement. problem solved. thank you very very very much for your helpd Quote Link to comment https://forums.phpfreaks.com/topic/102968-solved-how-to-make-variable-links/#findComment-527526 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.