Closed Thread Icon

Topic awaiting preservation: PHP If-Case-... (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12274" title="Pages that link to Topic awaiting preservation: PHP If-Case-... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP If-Case-... <span class="small">(Page 1 of 1)</span>\

 
ASP Newbee Programmer
Nervous Wreck (II) Inmate

From: Carinthia
Insane since: Jan 2002

posted posted 06-20-2002 08:18

This is the source of site, where the menu workes with variables. Every Link gives a parameter over the URL. The variable is $cat.
If I klick on a Link, the variable in the URL changes to "region" or "sport" or anything else. My Problem. The largest Part of the body is dependent to this variable $cat. But the body doesn´t change. The URL changes but nothing else happens.
Could anybody help me. Its very urgent.


if($cat) {
switch($cat) {
case 'region': echo "<img src=\"/grafik/balken/titel_region.gif\"><br><br><br>"; break;
case 'sport': echo "<img src=\"/grafik/balken/titel_sport.gif\"><br>";break;
case 'va': echo "<img src=\"/grafik/balken/titel_va.gif\"><br>";break;


Sorry for my english. I´am from Austria.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-20-2002 08:30

You can just do this.
if($cat) {
echo "<img src=\"/grafik/balken/titel_". $cat.".gif\"><br><br><br>";





.:[ Never resist a perfect moment ]:.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-20-2002 08:35

Well, your code appears to be fine... The problem is probably related to how PHP is configured. You didn't specify which version of PHP you have on server, so I'll talk generally. New versions of PHP come with "register_globals" option turned off (security reasons) and as a result parameters from URL won't be converted to variables automatically. If you have PHP version 4.1.0 or higher, replace all occurrences of "$cat" with "$_GET['cat']", otherwise replace all occurrences of "$cat" with "$HTTP_GET_VARS['cat']". Also, if you have any function which uses $cat variable and you have PHP version lower than 4.1.0, you'll need to add "global $HTTP_GET_VARS;" at the top of your function(s)...


ASP Newbee Programmer
Nervous Wreck (II) Inmate

From: Carinthia
Insane since: Jan 2002

posted posted 06-20-2002 08:36

This is the source of a friend. What means the switch?????
Is there another option to this If-Case????

ASP Newbee Programmer
Nervous Wreck (II) Inmate

From: Carinthia
Insane since: Jan 2002

posted posted 06-20-2002 08:39

I thank. It works. I didn´t knew about the versions.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-20-2002 09:07

Documentation for "switch" statement can be found here: http://www.php.net/manual/en/control-structures.switch.php

In your case it isn't necessary, because you can use $cat variable by directly outputting it (since your image filenames end with string contained in $cat variable), like in Bitdamaged example from above...


« BackwardsOnwards »

Show Forum Drop Down Menu