Splinter (http://splinter.comasu.de/index.php)
- Laberecke (http://splinter.comasu.de/board.php?boardid=3)
-- Technik (http://splinter.comasu.de/board.php?boardid=60)
--- PHP: mehrfache action-Anweisung über switch and case (http://splinter.comasu.de/thread.php?threadid=197)


Geschrieben von Ark am 26.03.2007 um 21:42:

  PHP: mehrfache action-Anweisung über switch and case

hallo mog

mal eine kleine frage^^
ich hab hier mehrere action-Anweisungen und würd gern wissen, wie ich das in eine switch and case-php-form fassen bzw. wie der ausgabecode aussehen kann?
hab mir zwar schon einige der wbb.php´s angeguckt, aber die sind irgendwie alle nochmal geschachtel -> also die mehrere $ in einer funktion enthalten

Quellcode

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
aktivierung in tpl
<a href="portal.php?portalinfo=1">1</a>
<a href="portal.php?portalinfo=2">1</a>
<a href="portal.php?portalinfo=3">1</a>

php-code
if ($portalinfo=="") { $text = "Ausgangsinfotext"; } 
if ($portalinfo=="1") { $text = "1 Infotext"; } 
if ($portalinfo=="2") { $text = "2 Infotext"; } 
if ($portalinfo=="3") { $text = "3 Infotext"; } 

ausgabecode in tpl
<if($portalinfo=="")><then>$text</then></if>
<if($portalinfo=="1")><then>$text</then></if>
<if($portalinfo=="2")><then>$text</then></if>
<if($portalinfo=="3")><then>$text</then></if>





Geschrieben von MoG am 26.03.2007 um 21:52:

 

Hiho

Eigentlich macht das kaum nen großen Unterschied, nur die Schreibarbeit ist ein wenig geringer und die Laufzeit der Abfragen evtl. kürzer ^^

Es sollte klar sein, dass die switch-Anweisung nicht in html-Dateien läuft, im gegensatz zu if-Abfragen, daher hier der PHP-Code

php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
switch($portalinfo) {
  case "1":
  $text "1 Infotext";
  break;

  case "2":
  $text "2 Infotext";
  break;

  case "3":
  $text "3 Infotext";
  break;

  default:
  $text "Ausgangsinformation";
}



Die If-Abfrage kannst du dir dann im tpl sparen ^^


mfg mog



Geschrieben von Ark am 26.03.2007 um 22:06:

 

super hat geklappt
gut wenn eine sache so systematisch aufgebaut ist^^

danke


Forensoftware: Burning Board 2, entwickelt von WoltLab GmbH