Announcement

Collapse
No announcement yet.

what i am doing bad, what's the problem?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • what i am doing bad, what's the problem?

    tengo un problema al "pasar" el siguiente script:

    <?
    if (isset ($HTTP_GET_VARS[id])) {
    $var = $HTTP_GET_VARS[id];
    }
    else {
    $var = "0002";
    }
    $item = substr($var,2,2);
    settype($item, "string");
    print ("$item"."<br>");
    if ($item = ("01")) {
    print ("normal"); }
    elseif ($item = ("02")) {
    print ("news"); }
    else {
    print ("Pagina no encontrada");
    }
    ?>

    the script writes the "02" but I cannot make the conditional "if" works and it writes "news", anyone can help me? what i am doing bad?

    thanks in advance

  • #2
    You have to use

    if($item=='01')

    instead of

    if($item=("01"))

    Comment


    • #3
      hehehe, I'm here because i have find my error no for search the solution, however I want to thank Icheb for his contribution!! a thousand of thanks!

      and now the question is: how can i be so stupid!!

      thanks again!

      Comment


      • #4
        = --> setting a value to a variable
        example:
        PHP Code:
        $var1 $var2 12
        settype
        ($var2"string");
        // $var1 is an integer with content 12, $var2 is a string with content "12" 
        == -> comparing CONTENT of both arguments. if one argument is of a different type than the other, php converts the type of the argument on the left to that one of the argument on the right side. this is not constant but only for this comparison
        example:
        PHP Code:
        if ($var1 == $var2) {
        // $var2 is string now, but will be handled as an integer for this comparison, 
        //cause the left argument is an integer. so, $var1 is 12, $var2 is 12 too (both 
        // integers). the result is true, but $var2 itsself is still a string

        === -> compares content AND type of both arguments
        example:
        PHP Code:
        if ($var1 === $var2) {
        // $var1 is an integer, $var2 is a string. even if both have the same content, 
        // this if-statement would return false

        what you did:
        PHP Code:
        if ($var1="abc") {
        // if statement checks now, if filling $var1 with content "abc" worked. of 
        // course it worked, so this statement is always true, and $var1 changed its 
        // value to "abc"


        sorry for my bad english I hope, you understand me anyway

        Comment


        • #5
          And then there is === , which checks if both variables have the same content and the same type.

          Edit: Never mind. Should have read your post to the end .

          Comment


          • #6
            a million of thanks for your contribution!
            Now I know more things about PHP and not only what I did bad, you (both) have explained me and explained to the community! and sorry my first post in this thread because I used spanish in the first paragraph, i didn't realised about it!

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X