pdpullmn612 Posted July 13, 2009 Share Posted July 13, 2009 Hey guys, I'm building a website and I have a question. I want my URLs to be in a format like so: http://mysite.com/resorts.php?resort=whatever On resorts.php Im dynamically listing links for different pages. What I want is that when a specific link is clicked, it displays the information of the selected link. I have been able to do this with includes and what not. There is only one problem. When a link is clicked I need the list of links on the top of the page to disappear, so that only the information of the page requested is displayed. I want it as if the link were clicked it basically looks like a whole new page, but maintains the URL format I specified above. I think I have done it before, but I cannot think of where I found out how I did it. Does this make sense? Any help would be great. Thanks in advanced. Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/165811-solved-php-links-using-_get/ Share on other sites More sharing options...
Box Posted July 13, 2009 Share Posted July 13, 2009 not really sure what your getting at. you can use an if to check what the variable is and then display various pages: ie: if($_GET['resort']) { echo ("The ".$_GET['resort']." is a nice place to go on holiday"); } else if ($_GET['caravanpark']) { echo ("Caravan parks are less fun, especially ".$_GET['caravanpark']); } Quote Link to comment https://forums.phpfreaks.com/topic/165811-solved-php-links-using-_get/#findComment-874627 Share on other sites More sharing options...
pdpullmn612 Posted July 13, 2009 Author Share Posted July 13, 2009 I'm looking for something like this: <?php include("dbconnection.php"); $sql = "SELECT name, abbreviation FROM resorts ORDER BY name ASC; $rs = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($rs)) { $output .= "<ul>"; while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $output .= "<li><a href=resorts.php?state=$row[abbreviation]>$row[name]</a></li>"; } $output .= "</ul>"; } print $output; $state = $_GET['state']; if(isset($state) { include($state . '.php'); //ex. This would display the contents of ct.php } else { include("index.php"); } ?> What I want is the content from lets say ct.php to show up, but the links generated above it to go away so im only left with the content of ct.php. I know I can use header("ct.php") to redirect the browser, but i want my links to be in the format like: http://www.mysite.com/resorts.php?state=ct instead of: http://www.mysite.com/ct.php hope that helps you guys better to help me. Thanks in advanced for your help. Quote Link to comment https://forums.phpfreaks.com/topic/165811-solved-php-links-using-_get/#findComment-874674 Share on other sites More sharing options...
Box Posted July 13, 2009 Share Posted July 13, 2009 <?php include("dbconnection.php"); if (!$_GET['state'] { $sql = "SELECT name, abbreviation FROM resorts ORDER BY name ASC; $rs = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($rs)) { $output .= "<ul>"; while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $output .= "<li><a href=resorts.php?state=$row[abbreviation]>$row[name]</a></li>"; } $output .= "</ul>"; } print $output; } else { $state = $_GET['state']; if(isset($state) { include($state . '.php'); //ex. This would display the contents of ct.php } else { include("index.php"); } } ?> like that? check to see if ?state was passed, if it was the don't show the list of links you have otherwise include the states page. Quote Link to comment https://forums.phpfreaks.com/topic/165811-solved-php-links-using-_get/#findComment-874681 Share on other sites More sharing options...
HERATHEIM Posted July 13, 2009 Share Posted July 13, 2009 switch(true) { case($_GET['state']=='ct'): { include("ct.php"); break; } } Quote Link to comment https://forums.phpfreaks.com/topic/165811-solved-php-links-using-_get/#findComment-874686 Share on other sites More sharing options...
pdpullmn612 Posted July 13, 2009 Author Share Posted July 13, 2009 Thanks box you're the man. Just what I was looking for. I kinda feel stupid for not thinking about that sooner. anyways, thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/165811-solved-php-links-using-_get/#findComment-874724 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.