Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Dynamic URLs (http://www.go4expert.com/forums/dynamic-urls-t2363/)

W3C 28Dec2006 02:21

Dynamic URLs
 
I have been trying to get pages that the address are:

example.com/forum/forum.php?t=3

I have been looking at tutorials and I have found stuff, but I don't quite get how it works and where to put the code that executes to make dynamic URLs.

Help or other tutorials would be great.
Thanks in advance,
W3C

shabbir 28Dec2006 05:46

Re: Dynamic URLs
 
Your forum.php script which is a PHP script should take into consideration the parameter passed (t=3) and should display the results based on the condition specified.

W3C 28Dec2006 07:59

Re: Dynamic URLs
 
Sorry I put a wrong example. Here is a better one:

example.com/index.php?page=browse

How would this code look to have an outcome of this address? Would it be just the '<a>' tag with the attibute of 'href="index.php?page=browse"', or how would you get a link to do that?

shabbir 28Dec2006 10:18

Re: Dynamic URLs
 
I am not able to get what you are asking. The parameter name and value will not make much of a difference provided it has been handled in the script. In the second example the script is index.php.

W3C 28Dec2006 10:34

Re: Dynamic URLs
 
What I want to know is how to get a link like a browse file and when clicked on have the address be:

example.com/index.php?page=browse

Example:
A site has home, browse, community, and contact us links. I want to know when the links are clicked on the address is:
browse = example.com/index.php?page=browse
community = example.com/index.php?page=community
contact us = example.com/index.php?page=contact_us

Is there a special code to execute that?

pradeep 28Dec2006 10:40

Re: Dynamic URLs
 
Are you suggesting that you want to include the files according to the parameter that is passed?? If that is what you want to do, that's very much possible to do.

W3C 28Dec2006 10:45

Re: Dynamic URLs
 
Yes that is what I want. Do you have a code that I may use?

pradeep 28Dec2006 10:53

Re: Dynamic URLs
 
That's is very simple, all you would need to do is to use a switch statement.
Here is a sample code,

Code: PHP

$page = $_GET['page'];

switch($page)
{
    case 'browse':
        include('browse.php');
        break;
    case 'contact_us':
        include('contact_us.php');
        break;
}


W3C 28Dec2006 10:56

Re: Dynamic URLs
 
Thanks for the code.
But what I don't really quite get is where to insert the code and how it works with links.

pradeep 28Dec2006 11:01

Re: Dynamic URLs
 
Insert the code in index.php, the logic is that according to the page parameter's value appropriate file is included and it's contents are executed, which as a result will change the output according to the parameter passed.


All times are GMT +5.5. The time now is 05:10.