Small PHP function, am I overlooking something? =/

Discussion in 'PHP' started by Chuckun, Jul 18, 2009.

  1. #1
    I'm trying to make a very makeshift language system... Defined by GET.

    This is what I've got..

    $lang == $_GET['lang'];
    
    if ($lang == "en") { $onlinetext1 == "visitors online"; $onlinetext2 == "visitor online"; } // Defines the different texts used later (in english)
    else if ($lang == "de") { $onlinetext1 == "Besucher online"; $onlinetext2 == "Besucher online"; } // Defines the different texts used later (in german)
    else { $onlinetext1 == "visitors online"; $onlinetext2 == "visitor online"; }
    
    // Singular or Plural?
    if ($total == "1") { $onlinetext3 == $onlinetext2; } else { $onlinetext3 == $onlinetext1; } // if the total is only '1' then we use the singular version, if its more than one, we use plural..
    		echo "document.write(\"<a href='$site_url' target='_blank'>$total $onlinetext3!</a>\");";
    PHP:
    The $total variable (previously defined, which is fine..) prints just fine, but the $onlinetext3 variable does not..

    Can anyone spot what I'm overlooking?

    Thanks for all help!

    Jack
     
    Chuckun, Jul 18, 2009 IP
  2. methomps

    methomps Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have comparison operators where I think you want assignment operators

    if ($total == "1") { $onlinetext3 == $onlinetext2; } else { $onlinetext3 == $onlinetext1; }
    PHP:
    should be

    if ($total == "1") { $onlinetext3 = $onlinetext2; } else { $onlinetext3 = $onlinetext1; }
    PHP:
     
    methomps, Jul 18, 2009 IP
    Chuckun likes this.
  3. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #3
    Hi, thanks for the response... However, I see no difference in those PHP codes? >.<

    edit: oh! the == vs =... I'll give it a try!

    Jack
     
    Chuckun, Jul 18, 2009 IP
  4. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yup you use 2 equals (==) when you want to compare to values(usually seen in the condition of if statements, as this is where comparisons occur), and you use a single equals (=) when you want to assign the right side of the equals to the left side of the equals.

    Hence == is a comparison operator and = is an assignment operator.

    e.g
    
    if($a == $b){
    //do this if $a has the same value as $b
    }
    
    $a = $b
    //This has set the value of $b to the value of $a
    $a = "Hello";
    //This has set the string "Hello" to $a
    
    PHP:
     
    wd_2k6, Jul 18, 2009 IP
    Chuckun likes this.
  5. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #5
    Ah!

    Your info was right methomps, however, the assignment operators had to be applied to every part of the code..

    Thank you so much! How foolish of me >.<

    +Rep for your help, thanks again!

    Jack

    EDIT: Thanks wd_2k6! Sorted it just as you posted, but thanks anyway! +rep :)
     
    Chuckun, Jul 18, 2009 IP