This forum is in archive mode. You will not be able to post new content.

Author Topic: PHP Question  (Read 1362 times)

0 Members and 1 Guest are viewing this topic.

Offline Nerotic7

  • Ultimate Faggot 9001
  • Knight
  • **
  • Posts: 151
  • Cookies: -37
    • View Profile
PHP Question
« on: May 27, 2013, 06:53:04 PM »
I am trying to learn PHP, and I just ran into a problem that I don't understand.


The problem:
<html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items =  6;   // Set this to a number greater than 5!
        if ($items > 5) {
             echo "You get a 10% discount!";
        } else {
        print "You get a 5% Discount";
       
        }
      ?>
    </p>
  </body>

My Instructions:
Go ahead and add an elseif condition to your if/else. It should check whether $items == 1, and it should echo or print "Sorry, no discount!"


I just really don't understand this.
Can someone give me some help with this?
Thanks
« Last Edit: May 27, 2013, 06:57:23 PM by Nerotic7 »
<@Phage> I was put in place ONLY to take care of you.

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: PHP Question
« Reply #1 on: May 27, 2013, 07:01:20 PM »
I don't get why you're so stumped?

Code: [Select]
  <?php
        $items 
=  6;   // Set this to a number greater than 5!
        
if ($items 5) {
             echo 
"You get a 10% discount!";
        }
        elseif (
$items == 1) {
              echo 
"Sorry, no discount!";
        }
        else {
        print 
"You get a 5% Discount";       
        }
?>

Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Snayler

  • Baron
  • ****
  • Posts: 812
  • Cookies: 135
    • View Profile
Re: PHP Question
« Reply #2 on: May 27, 2013, 07:05:48 PM »
<html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items =  6;   // Set this to a number greater than 5!
        if ($items > 5) {
             echo "You get a 10% discount!";
        } else {
        print "You get a 5% Discount";
       
        }
      ?>
    </p>
  </body>
My Instructions:
Go ahead and add an elseif condition to your if/else. It should check whether $items == 1, and it should echo or print "Sorry, no discount!"
First off, please try to avoid using different fonts and sizes, it's just annoying to the eyes.
Also, when posting code, use the [ code ] tags. On this case, you can use [ code=php ] (without the spaces), like this:
Code: (php) [Select]
      <?php
        $items 
=  6;   // Set this to a number greater than 5!
        
if ($items 5) {
             echo 
"You get a 10% discount!";
        } else {
        print 
"You get a 5% Discount";
        
        }
      
?>


Now, as for your question: You have an if/else statement and the instructions ask you to add an elseif statement. This is accomplished like this:
Code: (php) [Select]
<?php
       
if (condition1)
       {
          
command_to_run;
       }
       elseif(
condition2
       {
          
command_to_run;
       }
       else
       {
          
command_to_run;
       }
?>
Does that answer your doubts?

EDIT: Damn, vezzy beat me to it.
@vezzy: Giving the answer right away won't help him fully understand, he may just copy-paste. Just my $0.02.
« Last Edit: May 27, 2013, 07:07:35 PM by Snayler »

Offline Nerotic7

  • Ultimate Faggot 9001
  • Knight
  • **
  • Posts: 151
  • Cookies: -37
    • View Profile
Re: PHP Question
« Reply #3 on: May 27, 2013, 07:06:55 PM »
Thank you for your answers.
<@Phage> I was put in place ONLY to take care of you.

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: PHP Question
« Reply #4 on: May 28, 2013, 09:38:55 AM »
There is no reason (for you) to use print and echo at the same time, use one (echo).

Also please learn about programming, take up some very very very basic tutorials.
~Factionwars

Offline Nerotic7

  • Ultimate Faggot 9001
  • Knight
  • **
  • Posts: 151
  • Cookies: -37
    • View Profile
Re: PHP Question
« Reply #5 on: May 28, 2013, 07:51:31 PM »
There is no reason (for you) to use print and echo at the same time, use one (echo).

Also please learn about programming, take up some very very very basic tutorials.


I am learning PHP. That question was from my book
<@Phage> I was put in place ONLY to take care of you.

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.