PHP uvjetne naredbe - if...elseif...else

Riješimo zajedno jedan zadatak vezan za uvjetne naredbe u PHP-u, točnije za naredbu if...elseif...else.

 

 

Zadatak: Ako je vani sunčano vrijeme, potrebno je korisniku ispisati poruku: "Vani je lijep dan!".

Ako vani pada kiša potrebno je ispisati poruku: "Ponesi kišobran!".

Ako nije ni sunce ni kiša ispisat ćemo korisniku poruku: "Vani nije ni sunce ni kiša.".

 

Pogledajmo prvo kako bi izgledao dijagram tijeka za ovaj zadatak (upute za crtanje dijagrama tijeka možete pronaći OVDJE).

 

 

Za rješenje zadatka potrebno je prvo napisati malu html formu s jednim pitanjem (Kakvo je vrijeme?) i poljem za unos teksta.

 

Kod za tu formu bi izgledao ovako:

 

<form action="vrijeme.php" method="post">

<div>
<label for="vrijeme">Kakkvo je vrijeme vani?</label>

<input name="vrijeme" type="text" />
</div>
<div class="button">
<button type="submit">Potvrdi</button>
</div>

</form>

 

 

Ovaj kod potrebno je spremiti kao .html dokument naziva npr. forma_vrijeme.html.

 

Kada smo kreirali formu potrebno je napisati php skriptu koja će obrađivati podatke iz te forme.

Skriptu ćemo spremiti kao .php dokument, naziva npr. vrijeme.php. Dokument bi trebao sadržavati ovakav kod.

 

<?php

$vrijeme = $_POST["vrijeme"];

 

if ($vrijeme=="sunce")
   {
   echo "Vani je lijep dan!";
   }

elseif ($vrijeme=="kisa")
   {
   echo "Ponesi kisobran!";
   }

else
   {
   echo "Vani nije ni kisa ni sunce.";
   }


?>

 

Primjetite da je u html skripti upisan naziv php skripte (crveno).

Jednako tako u html skripti polje za unos tekstualnih podataka je nazvano vrijeme (zeleno), a u php skripti definirana je varijabla vrijeme čiji je sadržaj određen podacima koji se unesu u to polje u html skripti.

 

Gotov zadatak možete pogledati OVDJE.

 

 

Materijale izradila: Nikolina Jurić, Grafička škola u Zagrebu

 

 

 


Dodaj komentar

Comments

#18 Christiane 2015-01-13 06:17
Appreciating the persistence you put into your site and detailed information you offer.
It's good to come across a blog every once in a while that isn't
the same old rehashed information. Wonderful read! I've saved your site and I'm including your RSS feeds to my Google account.


My website ... tusze Gdańsk: http://www.tuszegdansk.pl
#17 Klara 2015-01-11 11:11
This info is priceless. How can I find out more?



Here is my web page - tusze: http://www.tonerkrakow.pl/
#16 Juliet 2015-01-10 04:16
Excellent site. A lot of helpful information here.
I'm sending it to some buddies ans additionally
sharing in delicious. And certainly, thanks for your sweat!


Here is my homepage: tusze warszawa: http://www.tuszewarszawa.pl/
#15 Arlen 2015-01-10 03:25
I do not even know how I ended up here, but I thought this post was great.
I don't know who you are but certainly you are going to a famous blogger if you aren't already
;) Cheers!

Here is my weblog :: tusze krakow: http://www.tuszekrakow.pl/
#14 Gilberto 2014-12-31 00:16
It'ѕ a shame yyou ԁon't have ɑ donate button! I'ԁ definitely donate
tߋ this superb blog! Ӏ suppose for noѡ і'll settle fߋr book-marking and adding
yourr RSS feed tߋ my Google account. Ӏ lοoκ forward tߋo fresh updates аnd will
share this site ѡith my Facebook ǥroup.
Talkk ѕoon!

my web blog :: Μaximum Shred - maximumshred.ߋrg.uk: http://maximumshred.org.uk/ -
#13 Mazie 2014-12-30 20:37
It would just like you drive a car on the top of a roadway!
Click "OK" to go back to the "System Properties" dialog box justt after which click "OK".
The bad display areas almost might look like they weee formed in ocean ocean.

Here is my web site ... Cracked glass iphone 4 apple
store: http://tommasomusarra.com/cracked-glass-iphone-4-apple-store.php
#12 Jonathon 2014-12-29 10:49
You have made somne good points there. I checked on the
web to find out more about the issue and found most individuals will go along with your views on this website.


Here is my blog; ps3 jailbreak 4.20: http://jailbreak-my-ps3.com/
#11 Monte 2014-12-27 16:07
Pretty gгeat post. Ӏ siply stumbled upon үoսr blog
ɑnd wanteԁ to say that I ɦave trսly enjoyed
browsing ƴouг weblog posts. Afteг all І'll bee subscribing iin ƴour rss feed аnd I
hope yߋu write once more vеry soоn!

Аlso visit my web-site :: spamvilla: http://spamvilla.com/
#10 Grover 2014-12-22 20:51
Next site gives more information about networking and network model.
Do check with your computer manufacturer what's the best
upgrade for your hardware before selecting any.
But do you know the right way to fix slow Internet.


My homepage - Cabbage patch kid dolls uk: http://vadoudmoazzen.com/cabbage-patch-kid-dolls-uk.php
#9 Thelma 2014-12-08 02:15
Ι don't even ҟnoѡ how I ended սp herе, but I thoսght thiѕ post was grеɑt.

Ι do not khow whho yoou are but definitely you'гe going to a famous
blogger if үou aгen't alreɑdy ;) Cheers!

Alѕߋ visit mү web page; tоp mba programs: http://spamvilla.com/bot-creation-service-2/recaptcha-ocr-with-60-accuracy-rent-available

Ocijenite sadržaj stranice:

Broj posjeta

1
Online

Srijeda, 27 Rujan 2023 21:42
Powered by CoalaWeb

Slanje materijala

 

Pozivaju se svi nastavnici općeobrazovnih i strukovnih predmeta u osnovnim i srednjim školama da se uključe u rad portala te nam pošalju svoje materijale za e-učenje, koje ćemo potom objaviti na našim stranicama.

 

Materijale šaljite na e-mail sdresu: eskola.ict4scf@gmail.com