Jump to content

[SOLVED] php links using $_GET


pdpullmn612

Recommended Posts

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

Link to comment
Share on other sites

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']);
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.