Welcome! Log In Create A New Profile

Advanced

PHP Three - Conditional Logic

Posted by 77928490 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
PHP Three - Conditional Logic
February 13, 2013 09:12PM
Quite a few operators to learn. Especially the priority of operators.

I have never seen === or !== so something new.

Done and dusted.
Re: PHP Three - Conditional Logic
February 17, 2013 07:53AM
Was Fun & fast section.
The "===" and "!==" is something new though
Re: PHP Three - Conditional Logic
February 18, 2013 01:03PM
Learning new things all the time! Done!
Re: PHP Three - Conditional Logic
February 18, 2013 09:21PM
XOR is also new to me.
Re: PHP Three - Conditional Logic
February 18, 2013 11:04PM
If statements, comparison operators and switch understood. Booleans will not be difficult, but I will have to be much more awake when tackling logical operators confused smiley, so I'm signing off for now....smile
Re: PHP Three - Conditional Logic
February 19, 2013 12:49PM
I found Conditional Logic more fascinating....busy with For Loops now
Re: PHP Three - Conditional Logic
February 19, 2013 02:46PM
Conditional logic are interestingsmile
avatar Re: PHP Three - Conditional Logic
February 19, 2013 06:56PM
I love if statements! I often use them to display different sidebars instead of loading my sites down with plugins.

As for switches, I normal use javascript which is very handy for displaying more information on a page without using to much visual space however the php take on it is rather interesting.

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Three - Conditional Logic
February 25, 2013 09:16PM
Wow very interesting chapter, tryin my best to absorb all this info.
Re: PHP Three - Conditional Logic
February 26, 2013 04:30PM
Conditional logic is not hard to understand especially if one already has a good understanding of maths. Understanding the switch statement was a challenge.
avatar Re: PHP Three - Conditional Logic
February 28, 2013 06:21AM
Good explanations for logical operators in this section. Found === and !== as well as precedence of operators interesting.
Re: PHP Three - Conditional Logic
February 28, 2013 10:32AM
alrighty section done and dusted.. knew most of them but is always nice to clarify and refresh the ones you dont use that often... off to the next section.. *slams door and storms off* grinning smiley

Student number : 7803-010-2
Email and Gtalk for support : wilcovandeijl@gmail.com
Re: PHP Three - Conditional Logic
March 06, 2013 02:01PM
great topic, something new learnt was === and !==, also the order of precedence was sumthn to take note of, I think the major challenge as a programmer is in responding and having to decide which conditional statement to use eg, if else vs switch, I would say keep 2 things in mind 1. use what is most suitable for the task at hand and 2. use what you are most comfortable with, bearing these two in mind you cant go wrong. If you are using plain text like notepad with no color codes to guide you on your coding be very careful of your curly brackets { and } to always open and close them.

..&ru..
avatar Re: PHP Three - Conditional Logic
March 09, 2013 08:09PM
Everything here is completely new to me. The topics are all well understood though, I am yet figuring how I would really apply this in my HTML tags.
Re: PHP Three - Conditional Logic
March 18, 2013 09:00AM
Hi guys.

Been very busy with PHP and C++(Other Unisa subject) this last two/three weeks.

Something interesting caught my eye with C++ on conditional statements.

I will explain everything below in the code section. I want to know if it is the same with PHP ?
The reason why I ask is because the level of depth is so much more in C++ than PHP although PHP is heavily based on C++.

In C++ or conditional statements you do not put curly brackets on some of your IF and ELSE statements even on some nested statements, because a ELSE statement will link to the closest IF statement that does not have curly braces(code blocks) as to how I understand it?

I know the moment you use curly braces you put one or more statements into a code block.

Again please correct me on the following if PHP work exactly the same with with nested IF and ELSE statements:

Language: PHP
if (condition1) if (condition2) statement1; else statement2; else statement3;     if (Codition1) { if (condition2) statement1; } else statement2;

Question2:

If you declare a variable in a IF or ELSE statement is that a local variable only valid to that IF or ELSE statement ?

Student Number: 78042879 (Part Time Courses)
avatar Re: PHP Three - Conditional Logic
March 18, 2013 12:57PM
As far as nested if statements go the minute you use an if within an else statement it becomes nested.

Language: PHP
<?php $var= x; $varx= xx;   if ($var >xxx) { $var=xx; print "some text here"; }   else { if ($var<xxxx) { $discount =.95; print "some text here"; } else { print "some text here" ; } }   ?>

As for C++, I've got more of a php brain, that "sharp" stuff just makes me confused.

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Three - Conditional Logic
March 18, 2013 01:31PM
Very cool section! Logical Operators were explained very well and I could understand all of this section. Curly brackets are very important so using a text editor such as Notepad++ is a great help in reminding you about these. On to the next section smiling smiley
Re: PHP Three - Conditional Logic
March 18, 2013 08:44PM
THX Shado77968239thumbs up

Student Number: 78042879 (Part Time Courses)
Re: PHP Three - Conditional Logic
March 18, 2013 08:51PM
Check out the CASE conditional logic. More applications are using it in place of many IF...ELSEs in a code. It is best for a program that should go though many alternatives.
Re: PHP Three - Conditional Logic
March 20, 2013 10:25AM
only funnies are === and !=== which could be useful, and a bit of a wierd precedence with AND and OR.
I think I'll stick with && and || unless I'm missing some neat trick.
avatar Re: PHP Three - Conditional Logic
March 20, 2013 12:28PM
Things are getting interesting now.
I have learned a lot in this chapter.
Will meet some of these == soonthumbs up
Re: PHP Three - Conditional Logic
March 20, 2013 04:08PM
Conditional logic is not hard to understand especially if one already has a good of maths and if u have programing b4
avatar Re: PHP Three - Conditional Logic
March 20, 2013 11:29PM
If statements are pretty straight forward.
The structure is similar if not the same as C# and javascript.
The way in which PHP code is read makes sense.
In an if statement, if the variable does not equal a certain value, the rest of the code in the if statement is ignored.
By the way, I could not find the kitten image. I managed to find the church image though.
The syntax for not equal to != looks familiar. I remember using this syntax in MS SQL Server.
The switch statement is useful when testing one variable.
I wonder if it is more efficient than an if statement.
If a switch statement is better than an if statement, performance wise, I would definitely choose it over an if statement.
I would think that the switch statement is more efficient. I stand corrected.
Logical operators are necessary when coding.
If there is a specific condition that needs to be met, logical operators can help you achieve this.
I was not aware that operators had a certain precedence. I will remember this.
I was not aware of the syntax === and !==
Re: PHP Three - Conditional Logic
March 21, 2013 11:09AM
Done with this chapter
Re: PHP Three - Conditional Logic
March 21, 2013 02:53PM
Nice chapter with a lot of meat to the bone.
Conditional logic is very useful.
Re: PHP Three - Conditional Logic
March 21, 2013 07:47PM
Anybody else missing scripts folder and selectPicture.php from the cd. And also kitten image file.
Re: PHP Three - Conditional Logic
March 21, 2013 08:20PM
Chapter 3 done. Switch statment is really neat way of getting away from being confused with multiple if then else statements so I can see myself using that syntax a lot. Not sure that I totally understand === and !== as didn't really understand 3 being the same as 'three'. Luckily we didn't have to go into that concept.
Re: PHP Three - Conditional Logic
March 21, 2013 08:34PM
I can answer my own question. After further searching I found the files I was looking for on the CD under the resources folder.
Re: PHP Three - Conditional Logic
March 26, 2013 03:15PM
What am i doing wrong?

The print for the code below is supposed to be "Sorry - No discount!" but it's giving me "10percent discount applies to this order!"

<?php

$total_spent = 90;
$discount_total = 100;

if ($total_spent > $total_discount) {

print("10 percent discount applies to this order!"winking smiley;

}

else if($total_spent < $discount_total) {

print("Sorry - No discount!"winking smiley;

}

?>

Please help!

78026962 afojonny
avatar
Mac
Re: PHP Three - Conditional Logic
March 26, 2013 03:58PM
use formatted code to post code. 5th button on editor here above.

elseif is one word.
avatar Re: PHP Three - Conditional Logic
March 26, 2013 07:30PM
What is $total_discount? smile

Sorry Mac but else if and elseif, both will result in the same behaviour but only if you use curly brackets. Only in C is the syntactic meaning a little different. It is considered good practice to use elseif when working with if and/or else.

afojonny got this script from PHP 3. 7. Less Than and Greater Than and in the script it is two words.

The problem with the script is his variable - he declared $discount_total but then called $total_discount?





afojonny Wrote:
-------------------------------------------------------
> What am i doing wrong?
>
> The print for the code below is supposed to be
> "Sorry - No discount!" but it's giving me
> "10percent discount applies to this order!"
>

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Three - Conditional Logic
March 26, 2013 10:07PM
Wow! You're a life saver 'Shado77968239'. I guess i had done too much for the day and i needed to take sometime off.

Thanks.

78026962 afojonny
avatar Re: PHP Three - Conditional Logic
March 26, 2013 10:36PM
Happy to help. Sometimes it's the simple things that trip us up.

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
avatar
Mac
Re: PHP Three - Conditional Logic
March 27, 2013 08:05AM
Shado77968239 Wrote:
-------------------------------------------------------
> What is $total_discount? smile
>
> Sorry Mac but else if and elseif, both will result
> in the same behaviour but only if you use curly
> brackets. Only in C is the syntactic meaning a
> little different. It is considered good practice
> to use elseif when working with if and/or else.

True. I forgot it is with colons that one must not separate it. However, one word is better smiling smiley
Sorry, only registered users may post in this forum.

Click here to login