My code works for me, but not others? Please help!

Discussion in 'PHP' started by Crayz, Feb 17, 2007.

  1. #1
    It seems my trim code isn't working properly for other people, but it works perfect for me. I have no idea what's going on, but heres a sample of my code:

    
    $added = "false";
    
    $array = split(",", "$addedusers");
    foreach($array as $key => $value)
    {
    if (trim($value) == $rdr){ 
    $added = "true";
    }
    }
    Code (markup):
    This is where it checks a string similar to 5623,765342,657431,998732 for the id $rdr which in this case might be.. 765342

    And heres where I check if someone is added or not:

    if($added=="false"){
    
    // CODE HERE
    
    }
    Code (markup):
    It seems the trim isn't working properly, when I put something in the code like..

    echo trim($value);

    It doesn't display the trimmed item for the other person, I guess I can call it. But it shows for me.

    Any ideas? I am getting very frustrated with this.
     
    Crayz, Feb 17, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    true and false do not require quotes or double quotes, by using them it will always evaluate to true, because infact you're setting the text "false" which has a numerical value > 1
     
    krakjoe, Feb 18, 2007 IP
  3. ColdMoney

    ColdMoney Peon

    Messages:
    65
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have tried your code already. it's work fine on my PC. :)
    I don't know what wrong that you found :confused:
     
    ColdMoney, Feb 20, 2007 IP
  4. Crayz

    Crayz Well-Known Member

    Messages:
    708
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    120
    #4
    Well it works good for me, but for others I guess it fails to work. I will post more of the code sometime today when I am not busy.
     
    Crayz, Feb 21, 2007 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Try this:

    $array = split('[,]', $addedusers);

    or

    $array = split(",", $addedusers);

    Bye :)
     
    JEET, Feb 22, 2007 IP
  6. Crayz

    Crayz Well-Known Member

    Messages:
    708
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    120
    #6
    That still didn't work for the other users, but works fine for me still :(

    Would anyone mind looking at my full code (the one php file) and try to figure out what I am doing wrong? The code is pretty messy, I was in a hurry when I made the script.

    Thanks!
     
    Crayz, Feb 22, 2007 IP
  7. psalzmann

    psalzmann Member

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    Hey there,

    I'm new here. Thought I'd shed some different light on things:

    
    $rdr = 765342;
    $values = array('5623','765342','657431','998732');
    $added = false;
    if (in_array($rdr, $values))
    {
        $added = true;
    }
    
    PHP:
    Regards,
    Peter
     
    psalzmann, Feb 22, 2007 IP
  8. Crayz

    Crayz Well-Known Member

    Messages:
    708
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    120
    #8
    I am trying the
    if (in_array($rdr, $values))
    Code (markup):
    you entered above, if this works i'll reply here :)
    I have to wait until my partner gets on, he's one of the people who it doesn't work for.
     
    Crayz, Feb 24, 2007 IP