Results 1 to 6 of 6

Thread: if statement

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    if statement

    i am more into vb6 programming then net and the if statement in vb6 i wonder how can i use similar thing in php

    just say in php form page

    simple basic will do

  2. #2
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: if statement

    if( $variable > 20 ) {

    }
    else{

    }

    those "{" means then and "}" means end

  3. #3

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: if statement

    looks hard will try

  4. #4
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: if statement

    lets write a program both in vb and php

    vp example:
    Code:
    dim x as integer
     x=0
    if x = 0 then
    Print "YES"
    else
    Print "NO"
    end if
    php example :
    Code:
    $x = 0;
    if ($x==0) {
    
    echo "YES";
    }
    else {
    echo "NO";
    }

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: if statement

    I would suggest you to look at some beginner level tutorials like in here: http://www.w3schools.com/php

    After going through it, try creating some small projects of your own with the ideas that you learned. Say some simple basic application like you did in VB6. Try making PHP versions of some of those VB6 apps you have.

    If you have any doubts, then get back to us and we will provide the solutions for your doubts. Without knowing the basics, it would really tough for you. PHP is easy to learn. Once you get the basics, it is easy as a pie.

    For development, if you are using a Windows PC, you can download and install WAMPserver or XAMPP.

    Good luck

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: if statement

    Ladoo, think of it like this (it's how i got used to it from VB)


    if VB you MAY put () around your IF. (wasted code but no real harm against it)

    #1 IF example, in VB:
    Code:
    IF A > B THEN 
       msgbox("yes")
    END IF
    is the same as
    #2 IF example in (still in VB):
    Code:
    IF (A > B) THEN 
       msgbox("yes")
    END IF
    in php you MUST use () around your condition.
    and in php you replace THEN with a { symbol and END IF with a } symbol

    so looking at example 2 again:
    #2 IF example in VB:
    Code:
    IF (A > B) THEN 
       msgbox("yes")
    END IF
    #2 IF example translated to php:
    Code:
    IF (A > B) {
       msgbox("yes");
    }
    once you get that down, the rest is easy.
    and here it is:



    instead of saying
    Code:
    IF (A = B) THEN
       do this
    END IF
    you have to use TWO == symbols.
    Code:
    IF (A == B) {
       do this
    }
    the reason is simple:
    php is stupid.

    in VB it knows that "Hey! i'm doing an IF because i saw the word IF!"

    but php it says "wait, what was i doing after i read that word IF?? OH! TWO == symbols! that means i'm doing an IF still!"

    vb vs php:

    Code:
    
      VB                     |       PHP
    ----------------------------------------------
    IF ( condition ) THEN      |  IF (condition) {
    ELSE                       |     } ELSE {
    END IF                     |        }
      IF ( A > B) THEN         |  IF (A > B) {
      IF ( A < B) THEN         |  IF (A < B) {
      IF ( A => B) THEN        |  IF (A >= B){...... (ALWAYS the > or < comes before the =
      IF ( A NOT B) THEN       |  IF (A != B) {
      IF ( A <> B) THEN        |  IF (A != B) {
      IF ( A = B) THEN         |  IF (A == B) {
    IF (A <> B AND C = D) THEN |  IF ((A != B) AND (C == D)) {
    
    
    VB:
    IF ( Cow > Moon AND Time = NIGHT) THEN
      Print "Cow Jumped Over The Moon At Night"
    ELSE
      Print "Something didn't go as planned and the cow got hurt"
    END IF
    
    PHP:
    IF ( (Cow > Moon) AND (Time == NIGHT)) {
      echo "Cow Jumped Over The Moon At Night";
    } ELSE {
      echo "Something didn't go as planned and the cow got hurt";
    }

    Now there are 3 things that still get me. they just take getting used to.

    First, VB is smart. It knows when it's done with a command.
    but after every PHP command you need to type that annoying semicolon. ;
    because, like i said, php just isn't that bright.

    Second: the == gets me very often.
    in PHP if you put one = instead of == then it will say IF ... OH, this = that so i must do { this }
    so many times i stared at a php IF THEN and simply couldn't see that i had one = instead of two == causing all of my problems.

    and last, remember the variable names are case sensitive.

    $Hello = "Hi"
    $hello = "bye"

    echo "i said $Hello then i said $hello.";

    output is:

    i said Hi then i said bye.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width