php links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pdpullmn
Forum Newbie
Posts: 5
Joined: Wed Jan 14, 2009 5:05 pm

php links

Post by pdpullmn »

Hey guys,

I am building a website and need a little help with php links.

Here is my current code.

Code: Select all

 
 
        <?php
            error_reporting(E_ALL ^ E_NOTICE);
            
            $sql = "SELECT id, stateName
                    FROM states
                    ORDER BY stateName ASC";
                    
            $rs = mysql_query($sql) or die(mysql_error());
            
            print "<ul id=\"state_nav\">";
            while($row = mysql_fetch_array($rs,MYSQL_ASSOC)) {
                print "<li>";
                print "<a href=\"resorts.php?state=".$row[id]."\">$row[stateName]</a>";
                print "</li>";
            }
            print "<ul>";
        ?>
 
 
What I want to know is how can I actually link to a page using this format. I want the URL in the to browser to read:

Code: Select all

http://www.mysite.com/resorts.php?state=CT
instead of:

Code: Select all

http://www.mysite.com/CT.php
I'm going for an effect similar to this:

Code: Select all

http://skiing.alpinezone.com/resorts/?state=CT
I read somewhere that I would need to use $_GET. I am kind of a beginner and don't really know how to do this. Any suggestions? If you nee more info let me know and I'll post it. Thanks in advance.

-Dave
pdpullmn
Forum Newbie
Posts: 5
Joined: Wed Jan 14, 2009 5:05 pm

Re: php links

Post by pdpullmn »

no help guys? is it that hard to do? lol
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php links

Post by califdon »

I'm not understanding your question. The code you showed will give the results you say you are looking for, apart from the difference between a fully qualified URL and a relative URL. Look in the Source Code in your browser.
pdpullmn
Forum Newbie
Posts: 5
Joined: Wed Jan 14, 2009 5:05 pm

Re: php links

Post by pdpullmn »

Ok I know what i have will give me the desired effect. However, I need to know how to get that link to actually bring me to that page. I know they do it with paginationg where it will be something like:

Code: Select all

http://www.mysite.com/index.php?page=5
And this actually brings you to page 5 of whatever.

Is there a way to do it in the context I'm using it in?

I have a database of 5 states and I have a link on a page to each state. I have an ID associated with each state that is taken from a database so when I roll my mouse over the link it says http://www.mysite.com/resorts.php?state=CT etc etc in the status bar on the bottom of the browser. Now what i wanna do is actually connect that link to a page that will bring me to that state's page.

Does that help you guys out a little more? If not let me know.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php links

Post by califdon »

What are you doing in resort.php? You should be using $_GET to find out what id was used, then a switch code block to determine what to do, probably send a redirect header to the appropriate URL.
pdpullmn
Forum Newbie
Posts: 5
Joined: Wed Jan 14, 2009 5:05 pm

Re: php links

Post by pdpullmn »

Yea I read somewhere that I would have to use $_GET, but I have no idea how to use it. Any explanations or examples?

Thanks
Post Reply