Jump to content


Photo

Switches? Cases?


  • Please log in to reply
1 reply to this topic

#1 yarub

yarub
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationSioux City, IA

Posted 03 March 2006 - 06:30 AM

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.

#2 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 03 March 2006 - 09:54 AM

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:

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


If you want to see it (for debugging reasons), use the following afterwards:
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.

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

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
- Humpty
  #> Where does the light go when it goes out?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users