Jump to content

Archived

This topic is now archived and is closed to further replies.

yarub

Switches? Cases?

Recommended Posts

I've visited websites that have one file, but multiple pages. I was told that these were called switches. Looked around the site and the net, but I don't really understand what I'm reading.

Could anyone give me an example of how to make these work? I'm referring to when a url says "index.php?do=page1" or "index.php?do=aboutme". Something like that. When you go to that certain part of the address, it takes you to a new page.... but on the same file.

Share this post


Link to post
Share on other sites
G'day dude,

You have lost me a little bit there with the new page but same file thing.

There are 2 ways of doing what you are asking both use what is refered to as switch, (nfi what case is, VB has that but I've not come accross it in PHP yet. Sae structure though).

You have for example index.php and you want it to do just about everything instead of having a whole lot of funky named files yeah?

You can do this with either buttons (forms) or links, (the file.php?variable=value&variable2=value).

An example:
index.php?var1=steve&var2=&var3=jiM(note that var2 = nothing. it doens't have to.

When you click on the link it loads a page with the ?etc... passed data. Retrieve that data by using the following:

[code]$Variable1=$_GET['var1'];
$Variable2=$_GET['var2'];
$Variable3=$_GET['var3'];
//You gotta do this BEFORE you need to use the data that you passed through[/code]


If you want to see it (for debugging reasons), use the following afterwards:
[code]echo "<BR><BR>-$Variable1-<BR>";
echo "<BR><BR>-$Variable2-<BR>";
echo "<BR><BR>-$Variable3-<BR>";
// the hyphens are optional I use them so that I can see if the value - nothing or a space or if there is a space at either end.[/code]

if you used the above example in your link then this would output the following:
[code](blankline)
(blankline)
-steve-
(blankline)
(blankline)
(blankline)
--
(blankline)
(blankline)
(blankline)
-jiM-
(blankline)[/code]

Let me know if you are following and we'll move on to the switch / case.


or let me know if you want to use buttons on forms instead. Noone will see the data that way.

If you want to use buttons on forms let me know if you know how the forms work too.

that way I'll know to explain them or not B 4 we move onto using them in conjunction with the SWITCH command/statement/syntax

Share this post


Link to post
Share on other sites

×

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.